0

当我设置 time Zome 时,locale time zone 仍然 datepicker 返回错误的时间。

datepicker.timeZone = [NSTimeZone localTimeZone];

它应该显示为 2012-04-20 12:20 但它显示的是 2012-04-20 12:02:42 + 0000

如何将印度的时区设置为 datepicker?

4

2 回答 2

2

我认为你应该设置你的 dateformatterLocale如下:

-(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]); 
}
于 2012-05-25T07:29:46.277 回答
0

对于日期选择器中的印度时区

目标 C

NSTimeInterval seconds = 5 * 60 * 60 + 30;
datePicker.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:seconds]; // Like GMT+5:30

在斯威夫特 3

let seconds: TimeInterval = 5*60*60 + 30
datePicker.timeZone = TimeZone(secondsFromGMT: Int(seconds))  // Like GMT+5:30
于 2017-06-19T10:13:14.017 回答