Re: Getting the GMT time
Re: Getting the GMT time
- Subject: Re: Getting the GMT time
- From: Steve Palmer <email@hidden>
- Date: Sat, 17 Apr 2004 09:49:38 -0700
OK, so what if I want to go the other way? Say I have a date which is
in GMT and I want to obtain the date in PST? I thought this would work:
NSDate * anObject = // an NSDate object
NSCalendarDate * anDate = [anObject dateWithCalendarFormat:nil
timeZone:[NSTimeZone timeZoneWithAbbreviation:@"PST"]];
but since my machine is in PST this just returns me the date unchanged.
If I substitute PST with GMT, it adds 8 hours to the date which is
wrong. What I want is for it to subtract 8 hours. I've looked through
the date/time APIs but I don't see anything obvious. What am I missing?
- Steve
On Apr 16, 2004, at 1:53 PM, Brian Bergstrand wrote:
>
-----BEGIN PGP SIGNED MESSAGE-----
>
Hash: SHA1
>
>
Here's an inline I use to get the GMT time.
>
>
static __inline NSCalendarDate* GMTDate(NSDate *d)
>
{
>
return ([d dateWithCalendarFormat:nil timeZone:[NSTimeZone
>
timeZoneWithAbbreviation:@"GMT"]]);
>
}
>
>
To get the current time, use the following:
>
>
id gmt;
>
gmt = GMTDate([NSDate date]);
>
>
HTH.
>
>
On Apr 16, 2004, at 3:11 PM, Frederick C. Lee wrote:
>
>
> Greetings:
>
>
>
> Is there a simple way to get the GMT time?
>
>
>
> The only viable way I know is to get the time offset from the local
>
> time zone and compute it.
>
>
>
> But is there a direct way to actually get the GMT?
>
>
>
> The following snippet I've tried but I get a nil result:
>
>
>
> NSTimeZone *t = [[NSTimeZone alloc] init];
>
>
>
> if ([t initWithName:@"GMT"] == nil) {
>
> NSLog(@"***** NULL Time zone???");
>
> }
>
>
>
> NSCalendarDate *GMTtime = [NSCalendarDate calendarDate];
>
> [GMTtime setTimeZone:t];
>
>
>
>
>
>
>
> I'm lost here.
>
>
>
> Regards,
>
>
>
> Ric.
>
>
>
Brian Bergstrand <http://www.bergstrand.org/brian/>, AIM: triryche206
>
PGP Key: <http://www.bergstrand.org/brian/misc/public_key.txt>
>
The word 'politics' is derived from the word 'poly', meaning 'many',
>
and the word 'ticks', meaning 'blood sucking parasites'. - Larry
>
Hardiman
>
As of 03:50:04 PM, iTunes is playing "Losing Myself" from "Tribe" by
>
"Queensrche"
>
>
-----BEGIN PGP SIGNATURE-----
>
Version: PGP 8.0.3
>
>
iQA/AwUBQIA5tXnR2Fu2x7aiEQJyFgCfcKmr+4i8uwDMATDzQi0o9WcZPokAnj92
>
xdXxB6f64I0yY30pNjHrDP3N
>
=VpU2
>
-----END PGP SIGNATURE-----
>
_______________________________________________
>
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.