Re: NSDate bug
Re: NSDate bug
- Subject: Re: NSDate bug
- From: "John C. Randolph" <email@hidden>
- Date: Mon, 26 Nov 2001 17:42:53 -0800
On Monday, November 26, 2001, at 04:45 PM, mikevannorsdel wrote:
>
I believe I found a bug in NSDate. I was trying to get the
>
epoch value for the current date doing:
>
>
unsigned long time = [[NSDate date] timeIntervalSince1970];
According to <Foundation/NSDate.h>:
typedef double NSTimeInterval;
So you're storing a double in an unsigned long.
BTW, that header also declares:
#define NSTimeIntervalSince1970 978307200.0
So you could just use
NSTimeInterval secondsSinceUNIXEpoch = [[NSDate date]
timeIntervalSinceReferenceDate] + NSTimeIntervalSince1970;
>
The correct epoch should be 1006821791 (Mon Nov 26 17:43:11 MST
>
2001). But the above returns 1104019824 (Sat Dec 25 17:10:24
>
MST 2004). Is this a known issue? Or did I miss something?
I'm a bit confused by your terminology. The "epoch" is the
instant from which the date values are offsets, so the UNIX
epoch is 00:00 hours, Jan 1, 1970, and the NSDate epoch is 00:00
hours, Jan 1, 2001.
Are you looking for the offset from the UNIX epoch, or from the
NSDate epoch?
-jcr
Support your right to protest a criminal nut-cult.
http://freehenson.da.ru/
References: | |
| >NSDate bug (From: email@hidden (mikevannorsdel)) |