StringFromDate returns the wrong year

#define stdDateFormat @"YYYYMMdd'T'hh:mm:ssZ" NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init]; [dateFormat setDateFormat:stdDateFormat]; NSString *TimeOfSync = [dateFormat stringFromDate:syncDate]; NSLog(@"date format: %@",stdDateFormat); NSLog(@"syncDate: %@",syncDate); NSLog(@"TimeOfSync: %@",TimeOfSync); 

Recorded Output:

 date format: YYYYMMdd'T'hh:mm:ssZ syncDate: 2009-01-03 19:00:00 +0000 TimeOfSync: 20080103T11:00:00-0800 

Can anyone help? The only thing I see is the extra space immediately before the time zone in the input line. Thanks.

+4
source share
1 answer

Use yyyy lowercase for year instead of YYYY.

The superscript Y indicates the year of the beginning of the week in which the date is located (January 3, 2009 - the week that begins in 2008).

See Unicode Date Format Templates .

+27
source

Source: https://habr.com/ru/post/1340379/


All Articles