Reputation: 604
While i am setting up time Zome ,locale time zone still datepicker returning wrong time .
datepicker.timeZone = [NSTimeZone localTimeZone];
It should display like 2012-04-20 12:20 but it is displaying 2012-04-20 12:02:42 + 0000
How can i set Time Zone of India to datepicker ?
Upvotes: 0
Views: 1636
Reputation: 417
For indian timezone in datepicker
Objective C
NSTimeInterval seconds = 5 * 60 * 60 + 30;
datePicker.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:seconds]; // Like GMT+5:30
in Swift 3
let seconds: TimeInterval = 5*60*60 + 30
datePicker.timeZone = TimeZone(secondsFromGMT: Int(seconds)) // Like GMT+5:30
Upvotes: 0
Reputation: 1313
i think you should set your dateformatter's Locale
like below:
-(void)localDate:(NSDate*)date
{
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd"]; // set your formatter how you want
NSDate * t = [dateFormatter dateFromString:[date description]];
//[dateFormatter setDateStyle:NSDateFormatterMediumStyle]; //you can set date format style
NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"yourLocalidentifier"] autorelease];
//you can reach your local identifier from here: [NSLocale availableLocaleIdentifiers]
[dateFormatter setLocale:usLocale];
NSLog(@"%@",[dateFormatter stringFromDate:t]);
}
Upvotes: 2