UTCDateTime????
UTCDateTime????
- Subject: UTCDateTime????
- From: Rainer Brockerhoff <email@hidden>
- Date: Wed, 1 Aug 2001 10:49:05 -0300
>
Date: Wed, 1 Aug 2001 03:03:22 -0700
>
From: Steve Gehrman <email@hidden>
>
>
I'm calling carbon to get the creation date of a file. Unfortunately
>
the creationDate value is a UTCDateTime.
>
>
How do I convert this to an NSDate?
Somewhat inelegant, but works:
UTCDateTime timeStamp; // this is the input
NSCalendarDate* date; // this is the output
union {
LocalDateTime local;
UInt64 shifted;
} u;
ConvertUTCToLocalDateTime(timeStamp,&u.local);
date = [NSDate
dateWithTimeIntervalSinceReferenceDate: u.shifted/65536.0-3061141200.0];
You may want to check the OSErr returned by ConvertUTCToLocalDateTime and assign some convenient "invalid" value to the date, or assign some default value to u.shifted. AFAIK ConvertUTCToLocalDateTime returns an error if the UTCDateTime is zero.
Hope this helps,
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
http://www.brockerhoff.net/ (updated July 2000)