2
2

More than 5 years have passed since last update.

iOSの5と7ではうまくいくのにiOS6でだけNSDateFormatterで取得できる年がおかしい

Posted at

2013年って指定しても2012となってしまう。

YYYY → yyyy で解決(´・ω・`)

     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
-    [formatter setDateFormat:@"YYYY-MM-dd"];
+    [formatter setDateFormat:@"yyyy-MM-dd"];
     NSDate *selectedDate = [formatter dateFromString:[NSString stringWithFormat:@"%4d-%02d-%02d", 2013, 11, 15]];
     NSLog(@"%@", [selectedDate description]);

参考
NSDateFormatter show wrong year

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2