GMT offset of Created file date
GMT offset of Created file date
- Subject: GMT offset of Created file date
- From: "James J. Merkel" <email@hidden>
- Date: Tue, 11 May 2004 07:11:54 -0700
I want to get the created file date of a file so I used some code which
is very similar to a code snippet which has been posted here before,
namely:
-(NSDate *)creationDateForFile:(NSString *)filename{
// Returns the creation date for 'filename' as an NSDate.
FSRef ref;
FSCatalogInfo catalogInfo;
OSStatus status;
OSErr err;
NSTimeInterval seconds;
NSCalendarDate *epoch = [NSCalendarDate dateWithYear:1904 month:1
day:1 hour:0 minute:0 second:0 timeZone:[NSTimeZone
timeZoneForSecondsFromGMT:0]];
[epoch setCalendarFormat:@"%Y:%m:%d %H:%M:%S"];
status = FSPathMakeRef([filename fileSystemRepresentation], &ref,
nil);
if(status != noErr){
return nil;
}
err = FSGetCatalogInfo(&ref, kFSCatInfoCreateDate, &catalogInfo,
NULL, NULL, NULL);
if(err != noErr){
return nil;
}
seconds = (double)((unsigned long
long)catalogInfo.createDate.highSeconds << 32) +
(double)catalogInfo.createDate.lowSeconds +
(double)catalogInfo.createDate.fraction / 0xffff;
return [epoch addTimeInterval:seconds];
}
However, the date I get returned by this code is offset by my time zone
difference from GMT. For example I get:
2004:04:11 21:32:00 returned whereas the created date in a Finder get
info window is: Sunday, April 11, 2004 2:32 PM, or seven hours earlier.
I have also tried other time zone constants like system time zone etc,
but get the same results.
Has anyone been able to get the correct time of a file created date?
Thanks,
Jim Merkel
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.