【发布时间】:2019-11-20 13:02:07
【问题描述】:
尝试使用日期格式将 UTC 转换为 BST(英国夏令时)。但它在日期结束时给了我“Z”。它适用于从 UTS 到 IST 的对话。下面是我的代码。
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setDateFormat:@"dd'-'MM'-'yyyy HH':'mm':'ss ZZZZZ"];
NSMutableString *dateString = [NSMutableString stringWithFormat:@"%@", [dateFormatter stringFromDate:[NSDate date]]];
NSLog(@"%@",dateString); // This prints 20-11-2019 12:49:02 Z
任何人都可以知道为什么会发生这种情况。代码有任何问题或需要更改吗?
【问题讨论】:
-
确切的输入是什么,确切的预期与实际结果是什么?
-
@luk2302 输入:2019-11-20 13:24:09 +0000([NSDate date]),预计:20-11-2019 13:22:59 +00:00
-
这仅适用于英国时间,因为它是当地时间和 UTC 相同。
标签: ios timezone nsdateformatter