Always i’m struggling with NSDate in iphone apps. I have developed one iphone app for US based client. The app should show the todays date. I have used the following code in my app. The date is showing correctly for me(Am in India). But, the date is also showing the india date for my client in (US). I want to show the date from the iphone/ipad device.
NSDate *today1 = [[NSDate alloc] init];
NSString *dates = [NSString stringWithFormat:@"%@",[today1 description]];
dates = [dates substringToIndex:10];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateStyle:NSDateFormatterBehaviorDefault];
[dateFormat setTimeZone:[NSTimeZone localTimeZone]];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
NSDate *date = [dateFormat dateFromString:dates];
How to do this? Any suggestions/sample code to solve this? I has spend 6 hours to solve my problem but, i didn’t find the answer? Please help me. Thanks to spend your valuable time with me.
Use Locale
See code blow Taken from here
Updated answer below
I have tested this should work out of the box any where is the world.