init]过去一小时返回日期? [英] init] returning date an hour in the past?

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

问题描述

当我调用

NSDate *now = [[NSDate alloc] init]; 

为了获取当前的日期和时间,我检查:

in order to get the current date and time, I check it with:

NSLog(@"Date now: %@", now);

输出的日期过去是一个小时。

the date outputted is one hour in the past.


2010-10-08 12:04:38.227
MiniBf [1326:207]现在:2010-10-08
11:04:38 GMT

2010-10-08 12:04:38.227 MiniBf[1326:207] Now: 2010-10-08 11:04:38 GMT

我的时区是否设置不正确?

Is my time zone set incorrectly somewhere perhaps?

谢谢!

Michael

推荐答案

使用NSDateFormatter本地化日期: p>

Use NSDateFormatter to localize the date:

NSLog(@"%@",[NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle]); 

这篇关于init]过去一小时返回日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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