NSDateFormatter giving the wrong Hour (+8 hours)
I don't undersatnd why I get 8:00AM instead of 00. This also happens if I set it to other hours.
Ok, I now tryed to present in a label the value of
[dateFormatter stringFromDate:dateTest];
And in a wierd way it presented the time I formatted... But if I check the NSDate object on a breakpoint then it says 08:00:00 and 开发者_Go百科not 00:00:00;
My best guess that you live in the States, which uses GMT -8 time zone at the date specified (maybe PST?). So the date has been parse correctly already, because it said it was GMT.
The dateFormat string is wrong. It should be
"yyyy-MM-dd-HH-mm-ss"
See http://unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns.
The main problems are
DD
is the day of year, not day of month. So 07 will override the month "November" set previously.hh
can only recognize numbers in the range [1, 12], which 0 is out of range.
精彩评论