How to enable NSString in NSDate?

I did not have enough brains. Can someone please tell me how I would convert this line:

"2011-01-13T17: 00: 00 + 11: 00"

in NSDate?

+5
source share
5 answers

Unicode date format format here

In addition, for your situation, you can try the following:

// original string
NSString *str = [NSString stringWithFormat:@"2011-01-13T17:00:00+11:00"];

// convert to date
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
// ignore +11 and use timezone name instead of seconds from gmt
[dateFormat setDateFormat:@"YYYY-MM-dd'T'HH:mm:ss'+11:00'"];
[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"Australia/Melbourne"]];
NSDate *dte = [dateFormat dateFromString:str];
NSLog(@"Date: %@", dte);

// back to string
NSDateFormatter *dateFormat2 = [[NSDateFormatter alloc] init];
[dateFormat2 setDateFormat:@"YYYY-MM-dd'T'HH:mm:ssZZZ"];
[dateFormat2 setTimeZone:[NSTimeZone timeZoneWithName:@"Australia/Melbourne"]];
NSString *dateString = [dateFormat2 stringFromDate:dte];
NSLog(@"DateString: %@", dateString);

[dateFormat release];
    [dateFormat2 release];

Hope this helps.

+20
source

put the T part in single quotation marks and check the unicode documents for accurate formatting. In my case, I have something similar that I am doing:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:@"YYYY-MM-dd'T'HH:mm:ss.SSS"];

, , . , nsdates.

, :

[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"America/New_York"]];
+3

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDate *dateT = [dateFormatter dateFromString:str];

+1

TouchTime.

https://github.com/jheising/TouchTime.

awesome strtotime PHP 5.4 Cocoa iOS. NSDate.

, , !

0

cocoapods. , , , .

" Cocoa NSDate ."

https://github.com/billymeltdown/nsdate-helper

:

NSDate *date = [NSDate dateFromString:@"2009-03-01 12:15:23"];
0

All Articles