NSDate and Date formatters
NSDate and Date formatters
- Subject: NSDate and Date formatters
- From: Adrian Bool <email@hidden>
- Date: Wed, 14 Jan 2004 11:59:57 +0100
Hi,
My app has a counter which I just want to display in
Hours:Minutes:Seconds using an NSDateFormatter.
The data for this counter is just an int (seconds) which is incremented
each second by an NSTimer. No problems there.
Here is where I initialize everything,
// init the counter
seconds = 0 ;
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]
initWithDateFormat:@"%H:%M:%S" allowNaturalLanguage:NO];
[timeRemainingTextField setFormatter: dateFormat] ;
[timeRemainingTextField setObjectValue:
[NSCalendarDate dateWithTimeIntervalSinceReferenceDate: seconds]] ;
Now I would expect my app would start off showing '00:00:00' as I have
have zero seconds from the reference date. Unfortunately I get
'01:00:00' which is rather annoying!
In the docs for NSDateFornetter there are two ways of specifying the
hour,
%H Hour based on a 24-hour clock as a decimal number (00-23)
%I Hour based on a 12-hour clock as a decimal number (01-12)
Where %H definitely seems to be the one I want - although I have tried
both and see no change.
I can get things to look correct by subtracting 60*60 from 'seconds'
just before I create the new NSCalendarDate, but that feels dodgy!
The Reference Date is supposed to be the 'start' of 1st Jan 2001.
Where 'start' is as accurate description as I can find. For the normal
unix time (from time(3) man page) it is defined as,
The time() function returns the value of time in seconds since 0
hours, 0
minutes, 0 seconds, January 1, 1970, Coordinated Universal Time,
without
including leap seconds.
The big question is - when did 1st Jan 2001 start for Cocoa? At
midnight on 31st Dec 2000 or at 1am on 1st Jan 2001?
Any suggestions for this unfortunate confused person!?
Thanks
aid
_______________________________________________
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.