Get Current date & time with [NSDate date]

点点圈 提交于 2019-12-03 01:00:27

问题


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

is it because of time zone ?

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


回答1:


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

or use

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]]);


来源:https://stackoverflow.com/questions/10772033/get-current-date-time-with-nsdate-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!