Hello,

I'm trying to set up a date formatter to convert a date string I receive from a 
server when downloading and sync'ing notes from web app. The dates I receive 
look like this:

2008-12-18 04:04:20.554442

The API docs for this web app specify that this is in GMT time, technically 
apparently UTC according to their forums. I'm trying to convert this into an 
NSDate using NSDateFormatter, which is all fine except for the milliseconds at 
the end. Here's my formatter:

dateFormatter= [[NSDateFormatteralloc] init];
[dateFormattersetFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormattersetDateFormat:@"yyyy-MM-dd HH:mm:ss.SSSSSS"];
//[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
[dateFormattersetTimeZone:[NSTimeZonetimeZoneWithAbbreviation:@"UTC"]];

The trouble is that whereas the milliseconds on the server are six digits long, 
I only ever get three digits, the last three always being zero.

For instance:

NSString*dateStr = @"2008-12-18 04:04:20.554442";
date = [dateFormatter dateFromString:dateStr];
[dateFormatter setTimeZone:[NSTimeZonesystemTimeZone]];
NSLog (@"%@", [dateFormatter stringFromDate:date]);

The output of this is:

2008-12-18 04:04:20.554000

It's not really a big deal, since any comparison I make will always be between 
rounded dates, so it shouldn't have any significant impact. However, I'm just 
wondering if I'm missing something here or doing something wrong - whether it 
is an error on my part that is causing the rounding (because an error on my 
part seems most likely :) ).

Thanks and all the best,
Keith


      
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to