Get Current date & time with [NSDate date]

user437064 picture user437064 · May 27, 2012 · Viewed 104.3k times · Source

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

Answer

Parag Bafna picture Parag Bafna · May 27, 2012
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]]);