Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting date format for NSDateFormatter

I am trying to set the date format for something like "2011-04-21 03:31:37.310396". I think I'm not getting the fractional seconds right. I'm looking at http://unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns for guidelines on how to specify it and I think my issue is in the format itself.

NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ssSSSSSS";     
NSDate* serverDate = [dateFormatter dateFromString:stringFormOfDate];    

Help?

like image 870
Joey Avatar asked Apr 21 '11 04:04

Joey


1 Answers

try

NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss.SSSSSS";     
NSDate* serverDate = [dateFormatter dateFromString:@"2011-04-21 03:31:37.310396"]; 

NSLog(@"%@", serverDate);

I guess you probably forgot the dot

like image 59
superandrew Avatar answered Sep 20 '22 10:09

superandrew