获取当前日期&时间与[NSDate日期] [英] Get Current date & time with [NSDate date]

查看:96
本文介绍了获取当前日期&时间与[NSDate日期]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统日期时间为5月26日22:55,但当我取得日期 [NSDate date] 日期时间为5月27日02:35

My system's date time is 26 May 22:55 but when i get date with [NSDate date] date time is 27 May 02:35

是因为时区?

如果是如何解决这个问题,当我得到日期时间,给我的系统日期,不检查时区

if yes how to solve this problem, that when i get date time, give me the date of my system and doesn't check time zone

推荐答案

NSLocale* currentLocale = [NSLocale currentLocale];
[[NSDate date] descriptionWithLocale:currentLocale];  

或使用

NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
// or @"yyyy-MM-dd hh:mm:ss a" if you prefer the time with AM/PM 
NSLog(@"%@",[dateFormatter stringFromDate:[NSDate date]]);

这篇关于获取当前日期&时间与[NSDate日期]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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