IST time zone not getting parsed

别说谁变了你拦得住时间么 提交于 2019-12-12 01:09:17

问题


I have a string Tue Feb 23 10:12:48 IST 2014, I want to get the NSdate object form this. I am using below code snippet

    NSString * buildTime = @"Tue Feb 23 10:12:48 IST 2014";
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"EEE MMM dd HH:mm:ss ZZZ yyyy"];
    NSDate *date = [formatter dateFromString:buildTime ];

Every time I am getting nil value to date variable. If I am changing IST to GMT in build time then NSDate is perfectly coming. Can any one correct me where I am doing mistake in this.


回答1:


Use small 'zzz' instead of 'ZZZ',

NSString * buildTime = @"Tue Feb 23 10:12:48 IST 2014";
NSLocale *indianEnglishLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_IN"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:indianEnglishLocale];
[dateFormatter setDateFormat:@"EEE MMM dd HH:mm:ss zzz yyyy"];
NSDate *date = [dateFormatter dateFromString:buildTime];
NSLog(@"date %@",date);
NSLog(@"string %@",[dateFormatter stringFromDate:date]);


来源:https://stackoverflow.com/questions/21746798/ist-time-zone-not-getting-parsed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!