[英]NSDate returns nil for 1933-01-01 00:00:00 in Singapore local time (SGT)
If you run this code you can see that the NSDate is always null for the 1933-01-01 00:00:00 +0000. 如果运行此代码,则可以看到对于1933-01-01 00:00:00 + 0000,NSDate始终为null。 Please help me how to resolve it.
请帮助我如何解决它。
NSString *date = @"1933-01-01 00:00:00 +0000";
NSString* dateString = [[NSString stringWithFormat:@"%@", date] stringByReplacingOccurrencesOfString:@" +0000" withString:@""];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"SGT"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
[dateFormatter setLocale:[NSLocale systemLocale]];
[dateFormatter setFormatterBehavior:NSDateFormatterBehaviorDefault];
NSDate* sgtDate = [dateFormatter dateFromString:dateString];
NSLog(@"SGT Date: %@",sgtDate);
Try 尝试
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+08:00"]];
Instead of 代替
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"SGT"]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.