What's the optimum way of storing an NSDate in NSUserDefaults?

前端 未结 4 769
旧巷少年郎
旧巷少年郎 2020-11-28 21:28

There\'s two ways of storing an NSDate in NSUserDefaults that I\'ve come across.

Option 1 - setObject:forKey:

// Set
NSDate *myDate = [NSDate date]         


        
4条回答
  •  忘掉有多难
    2020-11-28 22:21

    Use NSUserDefaults; dates are stored in Zulu time, so there are no time zone issues to worry about. Store it in your time zone, pull it out in another time zone, you'll be fine, the system handles the conversion (no date formatter to worry about).

提交回复
热议问题