Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong date showing in simulator of iPhone

Tags:

datetime

ios

ios5

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.

like image 959
NSCry Avatar asked Mar 06 '12 07:03

NSCry


People also ask

How do I change the Date and time on my simulator?

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.

How do you refresh iPhone simulator?

Selecting Reload (or pressing ⌘ + r in the iOS simulator) will reload the JavaScript that powers your application.

How do I change TimeZone in iOS emulator?

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 .


1 Answers

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]);
like image 173
saadnib Avatar answered Sep 21 '22 05:09

saadnib