Get Current date & time with [NSDate date]

Objective CCocoaNsdate

Objective C Problem Overview


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

Objective C Solutions


Solution 1 - Objective C

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser437064View Question on Stackoverflow
Solution 1 - Objective CParag BafnaView Answer on Stackoverflow