views:

1439

answers:

1

Hi

I am trying to convert a string to date in a separate time zone from the current system time zone. I have set the time zone of the dateformatter to this timezone. But the NSDate I get is always in my current time zone.

For instance, my current time zone is PDT. I have set the DateFormatter's time zone to CST. I have a string with the time in CST. But when I use date formatter to convert this string to date, I get the date in PDT, whereas I want it in CST.

Can someone please help.

Thanks.

+1  A: 

NSDate stores only the seconds since 00:00:00 01 Jan. 2001. The description of NSDate will use your current time zone (if try to debug with NSLog for example).

You must get the default time zone with

[NSTimeZone defaultTimeZone]

and then calculate the offset by using

-(NSTimeInterval)secondsFromGMT
cocoafan