Re: converting between strings, NSCalendarDates and back again
Re: converting between strings, NSCalendarDates and back again
- Subject: Re: converting between strings, NSCalendarDates and back again
- From: Jonathan Jackel <email@hidden>
- Date: Sat, 20 Mar 2004 09:20:31 -0500
Check out the NSTimeZone docs. You can set the default time zone to
GMT with:
[NSTimeZone setDefaultTimeZone:[NSTimeZone
TimeZoneForSecondsFromGMT:0]];
Then create your date object. Of course, once you change time zones,
your entire app will think it's on GMT, so you may want to reset the
default time zone once you are done. Or maybe not.
Jonathan
On Mar 19, 2004, at 8:25 AM, John Clayton wrote:
>
Hi Jonathan,
>
>
Thanks. I remembered descriptionWithCalendarFormat: after I had sent
>
this out.
>
>
I guess my real question is, can I create the date from a string like
>
the one below without adding the "GMT" and have the date be calibrated
>
in GMT instead of my system time zone?
>
>
>
On Mar 18, 2004, at 1:23 PM, Jonathan Jackel wrote:
>
>
> On Mar 17, 2004, at 10:23 PM, John Clayton wrote:
>
>
>
>> Hi,
>
>>
>
>> Say I have a date coming in as input to a framework method that looks
>
>> like this:Thu Oct 16 11:38:11 2003
>
>>
>
>> I know that the date is in the GMT timezone. I need to convert the
>
>> string to an NSCalendarDate (I think) and be able to return it in the
>
>> same format. I've tried doing this to get the date initialized:
>
>> NSString *dateStringForGMT = [myDateString
>
>> stringByAppendingString:@"
>
>> GMT"];
>
>> NSCalendarDate *newDate = [NSCalendarDate
>
>> dateWithString:dateStringForGMT calendarFormat:@"%a %b %d %H:%M:%S %Y
>
>> %Z"];
>
>>
>
>> which seems to work fine when creating the date. But is there some
>
>> magic to getting it to return the original string format when calling
>
>> -description but still retaining its proper time?
>
>
>
> It should be doing that already. That's what the docs for
>
> dateWithString:calendarFormat say. You can also try to set the date
>
> format with setCalendarFormat: or get the description in a particular
>
> format with descriptionWithCalendarFormat:
>
>
>
> Jonathan
>
> _______________________________________________
>
> 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.
>
>
>
>
>
-----------------------------------------------------------------------
>
"It is the truth that frees, not your attempts to be free."
>
- J. Krishnamurti
>
_______________________________________________
>
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.