NSDate不返回正确的日期 [英] NSDate not returning correct date

查看:85
本文介绍了NSDate不返回正确的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打印NSDate像这样:

I am printing NSDate like this:

NSDate *date = [NSDate date];
NSString *stringDate = [data description];

现在是2011年7月1日晚上11:43。我的iPod甚至说,在顶部的酒吧。但是stringDate打印出来:2011-07-02 03:43:46 +0000

Right now, it's July 1, 2011 11:43 pm. My iPod even says that on the top bar. But stringDate prints out: 2011-07-02 03:43:46 +0000

这显然是错误的。我使用NSDate百万次,但从来没有这个问题。什么可能是错误?
感谢

This is obviously wrong. I have used NSDate millions of times but never had this problem. What could be wrong? Thanks

推荐答案

您所在地区的时间偏移是 -04:00 ? NSDate将在显示日期时自动调整时间偏移。尝试,

Your region's time offset is -04:00? NSDate will automatically adjust the time offset when displaying the date. Try,

NSString *str = [date descriptionWithLocale:[NSLocale currentLocale]];

它会显示正确的日期。

这篇关于NSDate不返回正确的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆