nsdateformatter

how to convert datetime format in NSString?

柔情痞子 提交于 2019-12-03 20:27:36
问题 I have got value from the xml 2009-11-23T05:24:41.000Z . Now i want to display string like this: Wed, Nov 4, 2009 8:00 PM - Wed, Nov 4, 2009 9:00 PM How it possible? 回答1: You'll want to do something like this: NSDateFormatter * inputFormatter = [ [ [ NSDateFormatter alloc ] init ] autorelease ]; NSDateFormatter * outputFormatter = [ [ [ NSDateFormatter alloc ] init ] autorelease ]; [ inputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'.000Z'" ]; [ outputFormatter setDateFormat:@"EEE, MMM d,

Convert yyyy-MM-ddTHH:mm:ss.fffZ to DateTime in JavaScript manually

故事扮演 提交于 2019-12-03 19:58:05
问题 I receive from a Webservice a String with a date in this format: yyyy-MM-ddTHH:mm:ss.fffZ I need to convert that String with JavaScript to a normal DateTime but without using the new Date('yyyy-MM-ddTHH:mm:ss.fffZ') because I'm using an old version of JavaScript that not support that conversion. I can split that string and get the: Year Month Days Time but how to manipulate the time zone "fffZ" Any suggestions? 回答1: Here's a one liner from John Resig: var date = new Date((time || "").replace(

How change the date format which is stored in string? Objective c [duplicate]

空扰寡人 提交于 2019-12-03 17:34:43
This question already has answers here : Closed 8 years ago . Possible Duplicate: how to convert datetime format in NSString? I have stored date in string from json parsing. The format of date is 2011-1-24. Now i want to convert into MM-dd-YYYY format. For that i am using this code NSString *stringDate =[NSString stringWithFormat:@"%@",[list_date objectAtIndex:indexPath.row]]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM-dd-yyyy"]; NSDate *date = [dateFormatter dateFromString:stringDate]; NSString *newDate = [dateFormatter stringFromDate

Objective-C: Unicode Date Format

為{幸葍}努か 提交于 2019-12-03 14:18:42
I am trying to work out how to have the UNICODE representation of Sun, 03 May 2009 19:58:58 -0700 as eee, dd MMM yyyy HH:mm:s ZZZZ or something. I can't seem to get this working precisely. Use an NSDateFormatter . It lets you set a particular format string, using the format specifiers from the Unicode spec , then get the formatted date from a given NSDate object using stringFromDate: . Also consider reading Apple's doc about formatting dates . Example: // Given some NSDate *date NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateFormat:@"eee, dd MMM

iphone NSDate Conversion problem

女生的网名这么多〃 提交于 2019-12-03 13:54:52
问题 In my graph Api for facebook.. I am getting this data.. from Json.. "updated_time" = "2011-05-17T14:52:16+0000"; and I am using this code to convert it into valid date format NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease]; //2010-12-01T21:35:43+0000 [df setDateFormat:@"yyyy-mm-ddHH:mm:ssZZZZ"]; NSDate *date = [df dateFromString:[[forTable valueForKey:@"updated_time"] stringByReplacingOccurrencesOfString:@"T" withString:@""]]; [df setDateFormat:@"eee MMM dd, yyyy hh:mm"];

For iPhone OS 4.0 “dateFromString” method of NSDateFormatter returns nil

纵然是瞬间 提交于 2019-12-03 12:58:00
问题 I am using following code & its working perfectly fine in iPhone OS 3.2 +(NSDate *)NSDateFromString:(NSString *)dateString { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateStyle:NSDateFormatterShortStyle]; [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate *dateObj=[dateFormatter dateFromString:dateString]; [dateFormatter release], dateFormatter=nil; return dateObj; } But when I tried to use the

Inconsistent behaviour with NSDateFormatter on two different devices

∥☆過路亽.° 提交于 2019-12-03 12:03:01
问题 I'm having a bit of a problem with NSDateFormatter failing on one user's device (returning nil when parsing a string) and working perfectly when I run it locally (either in the simulator or on my device). I'm trying to rule out what could be causing a difference in this behaviour. My first thought was the locale but I've tried setting it explicitly to ensure the same locale is always used but it makes no difference. Here is the code: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]

NSDateformatter setDateFormat according to currentLocale

回眸只為那壹抹淺笑 提交于 2019-12-03 11:57:45
I'm going mad with, probably, a stupid problem. I have 3 strings: year, month and day. I need to have a date in the right format based on currentLocale, so i.e. if currentLocale localeIdentifier is en_US my dateFormat should be: MMM/dd/yyyy if it's fr_FR the dateFormat should be dd/MMM/yyyy I don't think the only way to do this is to get currentLocale localeIdentifier and start with a bunch of if then. Thanks in advance. Max Look at NSDateComponents to create an NSDate, then use NSDateFormatter to format it. NSDateFormatter uses the current locale to format dates, based on the format style (e

how to use NSDateFormatter to see “Today” string

孤街浪徒 提交于 2019-12-03 09:48:18
apple use it in the messages app for today messages Today 11:45 AM Yesterday 11:45 AM i see it in the apple developer site To specify a custom fixed format for a date formatter, you use setDateFormat:. The format string uses the format patterns from the Unicode Technical Standard #35. The version of the standard varies with release of the operating system: Calendar Fields fields ( alias | (field*, special*)) > field ( alias | (displayName?, relative*, special*)) > Translations may be supplied for names of calendar fields (elements of a calendar, such as Day, Month, Year, Hour, and so on), and

iOS - Friendly NSDate format

痴心易碎 提交于 2019-12-03 09:41:05
问题 I need to display the date of posts in my app to the user, right now I do it in this format: "Fri, 25 May". How would I format an NSDate to read something like "2 hours ago"? To make it more user friendly. 回答1: NSDateFormatter can't do things like that; you're going to need to establish your own rules. I guess something like: - (NSString *)formattedDate:(NSDate *)date { NSTimeInterval timeSinceDate = [[NSDate date] timeIntervalSinceDate:date]; // print up to 24 hours as a relative offset if