• 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: Dates and time zones
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dates and time zones


  • Subject: Re: Dates and time zones
  • From: Jonathan Jackel <email@hidden>
  • Date: Sat, 11 Dec 2004 13:04:18 -0500


On Dec 10, 2004, at 12:45 PM, Rory Prior wrote:

Hi all,

I've run into a slight problem dealing with natural language dates that include time zones in the format -0500, +0000 etc. Internally things seems to work fine - I can go [date description] and get back a string like "2004-11-29 15:30:00 -0500" which tells me NSDate has correctly parsed the natural language date and knows what the time zone is in its internal representation. However there is no way to get hold of that time zone information directly - you can't create an NSCalendarDate from an NSDate without supplying a time zone or using the system time zone which strikes me as being a bit retarded if the NSDate internally has a concept of what the time zone is.

I think you may be misunderstanding the nature of an NSDate. An NSDate represents a moment in time, with NO concept of what the time zone is. If you do


NSDate *aDate = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:3600];

you get an object representing a moment in time that is 1 am GMT on 1 Jan 2001, but is also 8 pm EST on 31 Dec 2000. When you do [date description], the resulting string uses an arbitrary time zone. If I had to guess, it would be the user's time zone, but I haven't tested that and the docs don't say. The methods -descriptionWithCalendarFormat:timeZone:locale: and friends exist so you can express that moment in time as it is understood in various time zones.

So, no, it's not retarded.  But it may not be what you need.



My aim is translate dates into a 'friendly' form like this: "November 29, 3:30 pm EST".


I tried doing some string parsing to grab the ±0000 part of the date, which I could then convert into seconds and use to create an NSTimeZone - which would be great, but that will only give me GMT -0500 back again if I call it's name or abbreviation methods which is no better than what I started with. I'm amazed it doesn't seem to understand the relationship between an offset in hours from GMT and all the named time zones as you'd think this was essentially the job of this class. So do I need to reinvent the wheel here or am I missing something, perhaps in another class?

If you want to deal with dates somewhat more conventionally, i.e., explicitly anchored to a particularly time zone, initialize them as NSCalendarDates.


Jonathan

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Dates and time zones
      • From: Rory Prior <email@hidden>
References: 
 >Dates and time zones (From: Rory Prior <email@hidden>)

  • Prev by Date: Re: Localized decimal point?
  • Next by Date: ftp in cocoa apps
  • Previous by thread: Dates and time zones
  • Next by thread: Re: Dates and time zones
  • Index(es):
    • Date
    • Thread