Abhinav
Abhinav

Reputation: 38172

Converting GMT date format to locale based format

How can we convert NSDate object in GMT format to the date format with current locale/device settings?

For example if a device is in US and in PDT time zone then I want to convert GMT time to its equivalent PDT time.

Upvotes: 0

Views: 829

Answers (2)

Ole Begemann
Ole Begemann

Reputation: 135588

Strictly, you cannot convert an NSDate to another time zone because NSDate has no conception of time zones whatsoever. An NSDate object simply represents a single point in (absolute) time, regardless of time zone.

Whenever you want to display a date to the user, you should create an NSDateFormatter. By default, it automatically displays time in the user's time zone. You can override this with -[NSDateFormatter setTimeZone:].

Upvotes: 1

CRD
CRD

Reputation: 53010

Just use the NSDate method descriptionWithCalendarFormat:timeZone:locale: passing in the appropriate timezone. If you just use the description method you get the date/time in the current timezone (so if the device is set to PDT the time will be in PDT).

Upvotes: 0

Related Questions