Christian Gossain
Christian Gossain

Reputation: 5972

Getting the date for the users current time zone?

When using NSDate to get today's date, I seem to be getting a date that is ahead in time. For example, today is February 19 but NSDate is giving me February 20?

What can I do to get the proper date?

Upvotes: 0

Views: 386

Answers (1)

Ole Begemann
Ole Begemann

Reputation: 135550

I'm using NSDate *today = [NSDate date]; to get todays date but the problem is that it's not in my current time zone.

This sentence doesn't make sense. An NSDate object represents a single point in time, regardless of time zone. NSDate does not even have a sense of time zones.

To output a date as a string, always create an instance of NSDateFormatter and call its stringFromDate: method. By default, NSDateFormatter uses the current user's time zone.

Upvotes: 3

Related Questions