I have a row in my plist using a Date type. I manually set to the date to Jan 1, 1970 12:00:00 AM. I'm using the plist as defaults for NSUserDefaults
. When I read the value using NSUser开发者_StackOverflowDefaults
, it returns 1970-01-01 08:00:00 +0000. As a result, this check always fails:
if ([defaultDateFromPlist isEqualToDate:[NSDate dateWithTimeIntervalSince1970:0]])
// this never evaluates to true since the time is returning 08:00:00
What date do I type in my plist to make sure the default is equal to [NSDate dateWithTimeIntervalSince1970:0]
?
In the Xcode project navigator you can right-click on the plist file and select Open as Source Code. This will allow you to edit the file in its raw XML form.
From there you can set the time more precisely using "Z". So you can have something like this:
<key>startDate</key>
<date>1970-01-01T00:00:00Z</date>
Time zones strike again! The date you're comparing to is 00:00 GMT on 1/1/1970, not 00:00 in your local time, so you'll need to specify a time zone in the date in the plist. Try using the same "+0000" suffix in the plist as you got in the output, and you should be fine.
精彩评论