IST 时区未解析 [英] IST time zone not getting parsed
本文介绍了IST 时区未解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串 Tue Feb 23 10:12:48 IST 2014,我想从这里获取 NSdate 对象.我正在使用以下代码片段
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 ];
每次我为 date 变量获取 nil 值时.如果我在构建时将 IST 更改为 GMT,那么 NSDate 即将到来.任何人都可以纠正我在这方面做错的地方.
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.
推荐答案
使用小号'zzz'代替'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]);
这篇关于IST 时区未解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文