本文介绍了NSDate返回错误的年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MyappAppDelegate.m文件中的应用程序:didFinishLaunchingWithOptions:"方法中,我刚刚写道:

In MyappAppDelegate.m file at "application: didFinishLaunchingWithOptions:" method, I just wrote:

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy"];
NSDate *date = [NSDate date];
NSLog(@"%@", [df stringFromDate:date]);
return;

并与iPhoneSimulator一起运行,控制台说:

And ran with iPhoneSimulator, console said:

我不明白发生了什么事.

I can't understand what's happening.

因此,我创建了新的Xcode项目并进行了如上所述的测试,然后正确返回了'2010'.我在Myapp中做了一些错误的设置吗?

So I created new Xcode project and tested like above, then it correctly returned '2010'. Did I do some bad settings in Myapp?

谢谢.

  • iOS SDK 4.1
  • Xcode 3.2.4
  • using libraries: http://github.com/klazuka/Kal, ttp://www.tbxml.co.uk/TBXML/TBXML_Free.html

推荐答案

您正在使用日语日历.
检查设置/常规/国际/日历.将其重新设置为公历.

You are using the japanese calendar.
Check Settings/General/International/Calendar. Set it back to gregorian.

这篇关于NSDate返回错误的年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-20 22:42