What is the best way to store dates that represent just date, not the time.
This code gives me this in console - I'm in Central European time zone:
"Raw: 2009-12-30 23:00:00 +0000, Str: 31.12.2009."
Somehow I think this may turn out as a problem. If my app puts this date into a file, then reads it in another time zone it may turn as Dec 30 even in -stringFromDate: and that is not what I want. That is a date of a real paper document and if the document was marked with Dec 31 then that is the date of the document, wherever observer may found himself.
What should I do to store dates that are stable across time zones?
Code:
void TestDate (void)
{
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:31];
[comps setMonth:12];
[comps setYear:2009];
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *dt = [cal dateFromComponents:comps];
[comps release];
[cal release];
NSDateFormatter *dfmt = [[NSDateFormatter alloc] init];
[dfmt setDateStyle:kCFDateFormatterShortStyle];
NSString *dateString = [dfmt stringFromDate:dt];
[dfmt release];
NSLog (@"Raw: %@, Str: %@", dt, dateString);
}
This code gives me this in console - I'm in Central European time zone:
"Raw: 2009-12-30 23:00:00 +0000, Str: 31.12.2009."
Somehow I think this may turn out as a problem. If my app puts this date into a file, then reads it in another time zone it may turn as Dec 30 even in -stringFromDate: and that is not what I want. That is a date of a real paper document and if the document was marked with Dec 31 then that is the date of the document, wherever observer may found himself.
What should I do to store dates that are stable across time zones?