Convert GMT date format to locale-based format

advertisements

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.


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:].