Re: NSDate without time portion
Re: NSDate without time portion
- Subject: Re: NSDate without time portion
- From: glenn andreas <email@hidden>
- Date: Tue, 05 Jan 2010 13:59:00 -0600
On Jan 5, 2010, at 1:48 PM, Karolis Ramanauskas wrote:
>>
>> By formatting the dates as YYYYMMDD and keeping them in strings you can use
>> simple string comparison to sort, compare and filter. They are also very
>> easy to format for display purposes. If you want to go standard then use the
>> ISO 8601 date format. It's YYYY-MM-DD. See
>> http://www.iso.org/iso/date_and_time_format
>>
>
> Great, but do not forget, in this case, to store time zone information too,
> perhaps in a separate string. Time offset won't do because it may change for
> the same time zone depending on daylight savings time. If I store date as a
> string, I also store the associated time zone's "name" property. NSDate is
> more than a plain date. It has time zone info embedded.
No it doesn't. NSCalendarDate has a timezone, NSDate does not.
> Just try printing
> the same date object on daylight savings time date and not, and you will see
> the date object automatically adjusts the time. So, hypothetically if you
> stored 2009-12-31 as a string. Then created NSDate object from that string.
> It may later be interpreted as 2009-12-31 00:00:00 or, let's say 2009-12-30
> 23:00:00 or 2009-12-31 05:00:00, if the time zone of your user computer
> changes. Think, what if you user saves an appointment at 12:00:00 in New
> York and you store it as a string with no time zone info? In Chicago, that
> appointment will appear at 12:00:00 also even though it is really happening
> at 11:00:00.
NSDate conceptually store time relative to Jan 1, 2001, GMT.
When it is formatted for display, it uses the current time zone (or more correctly, the NSDateFormatter uses whatever time zone has been specified, or the current system time zone). If your time zone changes (such as by daylight savings time, or changing the location), the resulting date will print differently, but timeIntervalSinceReferenceDate will be unchanged. It is ultimately the date formatter that handles time zones, daylight savings time, etc...
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
Mad, Bad, and Dangerous to Know
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden