I am using this code
NSDate *today = [NSDate date];
NSLog(@"%@",today);
In console it is showing
0024-03-06 07:51:46 +0000
Everything is ok except the year.It's showing wrong year(0024).It should be (2012). Can anyone tell me how shall I get correct code.
My mac system date is right.
At any time, highlight your toolbar, choose the cloud icon, and a panel with date and time settings will appear. Similar to the options on the map screen, you can adjust the date and time while flying around.
Selecting Reload (or pressing ⌘ + r in the iOS simulator) will reload the JavaScript that powers your application.
How do I change time and time zone in the iPhone simulator? You can set the TZ environment variable in an Xcode Scheme to set the time zone just for that app. You can use UTC , PST , EST , as well as place-based timezone names such as America/Los_Angeles .
Please check your iPhone simulator calendar settings in Settings -> General -> International -> Calendar ->
Your current calendar is Japanese, if you set it to Gregorian then your problem will resolve.
and you also change it by using NSDateFormatter if you don't want to change your simulator settings -
NSDate *today = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setCalendar:calendar];
[dateFormat setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSLog(@"date = %@",[dateFormat stringFromDate:today]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With