开发者

Getting the date for the users current time zone?

开发者 https://www.devze.com 2023-02-11 07:03 出处:网络
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 1开发者_如何转开发9 but NSDate is giving me February 20?

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 1开发者_如何转开发9 but NSDate is giving me February 20?

What can I do to get the proper date?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消