简体   繁体   English

NSDate在今天前一天获得值

[英]NSDate get the values one day before today

I try to get date today using this code: 我尝试使用以下代码获取日期:

NSDate *today = [[NSDate alloc] init];
NSLog(@"Today: %@", today);

the result is: 结果是:

January 30, 2013 +00:00:00 2013年1月30日+00:00:00

But the current date is 但是当前日期是

January 29, 2013 +00:00:00 2013年1月29日+00:00:00

Any idea, to how solve this case? 任何想法,如何解决这种情况?

Why not just 为什么不只是

NSDate* today = [NSDate date];

Also, remember that if you look at "today" you will see the date in GMT, not your local time. 另外,请记住,如果您查看“今天”,则会看到格林尼治标准时间的日期,而不是当地时间。

OK, here are two things to check out: 好的,这有两件事要检查:

  1. Make sure the clock of the device is set correctly. 确保设备的时钟设置正确。
  2. Make sure you are using the correct time zone. 确保使用正确的时区。

Ingo. 英戈

Try This: 尝试这个:

NSLog(@"Today: %@",[today  descriptionWithLocale:[NSLocale currentLocale]];

NSDate returns date in GMT .Above will convert date in your currentLocale . NSDateGMT返回日期。以上将日期转换为您的currentLocale

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM