In our app, we always need to pick the current Eastern time (EST or EDT).
We set the application timezone as below in the app delegate:
NSTimeZone *ESTTimeZone = [NSTimeZone timeZoneWithName:@"US/Eastern"];
[NSTimeZone setDefaultTimeZone:ESTTimeZone];
Also, for the NSDateFormatter, we set the locale as follows:
NSDateFormatter *formatForFileName = [[NSDateFormatter alloc] init];
[formatForFileName setDateFormat:@"yyyyMMdd"];
NSLocale *uslocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[formatForFileName setLocale:uslocale];
[uslocale release];
If my iPad is set to correct EST date and time, there is no issue. If I were to log the current date as follows:
NSLog(@"current date : %@",[formatForFileName stringFromDate:[NSDate date]]);
it will display today's date correctly. However, if I change my iPad date to be the next day's date and log the current date, I would want the current EST date and time to be returned. However, [NSDate date] returns me the current iPad date (the next day's date) and time and not the EST date and time.
Is there any way I can get the correct EST date and time using [NSDate date] irrespective of what the user has set on his iPad.
Thanks.