日期格式化程序在转换为字符串 Objective-C 时给出错误的日期

问题描述:

我正在将日期转换为文本以显示在文本框中,并且转换得很好.2013 年 12 月 29、30 和 31 日转换为 2014 年,2014 年 12 月 29、30 和 31 日转换为 2015 年.

I'm converting a date to text to display in a text box and it converts fine. The 29,30 and 31 December 2013 gets converted to 2014 and 29,30 and 31 December 2014 gets converted to 2015.

这是我将日期转换为文本的代码

This is my code to convert the date to text

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd MMM YYYY"];
self.pickupDateTextField.text = [dateFormatter stringFromDate:[self.datePicker date]];
NSLog(@"%@ %@",self.datePicker.date,self.pickupDateTextField.text);

这就是 NSLog 正在打印的内容.

This is what the NSLog is printing.

2013-12-29 06:58:14 +0000 29 Dec 2014

正确的日期格式化字符串如下:

The correct date formatter string is as below:

[dateFormatter setDateFormat:@"dd MMM yyyy"];

它应该有小写的yyyy"而不是大写的YYYY".

It should have small "yyyy" and not the capital "YYYY".