如何获取本地日期和时间?
我正在使用 NSDate 获取当前时间和日期,但它给出的日期和时间基于 GMT。请问有人知道如何获取当地时间吗?
提前致谢!
I am using NSDate to get current time and date but it is giving date and time based on GMT.Please can anyone know how to get local time?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NSDate 不了解时区。它始终将日期存储为绝对时间(GMT)。
使用 NSDateFormatter 获取本地(或任何其他时区)表示。
请参阅相关的编程指南:http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html
NSDate has no knowledge of timezones. It always stores dates as absolute moments in time, in GMT.
Use NSDateFormatter to get a local (or any other time zone) representation.
See the pertinent programming guide: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html
使用日期格式化程序通过上述方法设置日期的时区。它会起作用的。将日期转换为字符串,设置格式和时区,然后转换回日期。
set the timezone of the date using a date formatter with the above method. It will work. Convert the date to string, set the format and timezone and convert back to date.
您好,我从另一个网站找到了
这个网站链接是 此处
Hi I found this from another site
Link for the website is here