• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDate and Date formatters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSDate and Date formatters
      • From: Adrian Bool <email@hidden>
    • Printing two views in a single print job
      • From: Gideon King <email@hidden>
References: 
 >NSDate and Date formatters (From: Adrian Bool <email@hidden>)
 >Re: NSDate and Date formatters (From: Daniel Todd Currie <email@hidden>)
 >Re: NSDate and Date formatters (From: Adrian Bool <email@hidden>)

  • Prev by Date: Re: NSTask, Perl, HTML
  • Next by Date: Re: NSCacheImageRep woes
  • Previous by thread: Re: NSDate and Date formatters
  • Next by thread: Printing two views in a single print job
  • Index(es):
    • Date
    • Thread