Re: NSDate and Date formatters
Re: NSDate and Date formatters
- Subject: Re: NSDate and Date formatters
- From: "Louis C. Sacha" <email@hidden>
- Date: Wed, 14 Jan 2004 16:34:07 -0800
Hello...
NSCalendarDate has a method -(void)setTimeZone:(NSTimeZone *)zone,
which you should be able to use to set the time zone of the
NSCalendarDate to GMT. I haven't tested it, but the following should
work the way you want:
/* typed in mail, etc... */
NSCalendarDate *elapsedTime = [NSCalendarDate
dateWithTimeIntervalSinceReferenceDate: seconds];
[elapsedTime setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
[timeRemainingTextField setObjectValue:elapsedTime] ;
It might be a bit more efficient to store the NSTimeZone instance as
an instance variable instead of making a new autoreleased one each
time, since you are likely updating the counter every second...
Hope that helps...
Louis
Hi Daniel,
On 14 Jan 2004, at 12:36, Daniel Todd Currie wrote:
What time zone are you in (what time zone does your computer think
you're in)?
Suspiciously, both myself and my computer are on CET, +1 GMT....
I am in US PST, which is GMT -8. [NSDate
dateWithTimeIntervalSinceReferenceDate:0] returns 2000-12-31 16:00
for me, which is exactly what it should be, since the reference
date is based on GMT. Remember we are working with dates, not time
intervals.
Perhaps I simply don't have all the details, but what do you need
this counter for anyway? The system clock is a perfectly good
timer... I would think an easier way to do this would be to init
an NSDate where you init the counter, and then you can get your
counter value with:
[[NSDate date] timeIntervalSinceDate:initDate]
All the program is a Minesweeper clone for me to learn Cocoa! I
want to pause the increment of 'seconds' when the window is hidden.
Your code suggestion above would not fit with that goal very well.
This would eschew all the confusion over reference dates and
worries about your user's time zone.
Just my 2 cents anyway...
Well, you were completely right! I changed my timezone to PST and
can see a new different value in my counter. MMm. will need to
think what to do next. Thanks for the help.
Regards,
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.
_______________________________________________
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.