为什么从 UTC 转换为 BST 时 'Z' 处于日期的末尾?

Why 'Z' is at the end of date while converting from UTC to BST?

尝试使用日期格式从 UTC 转换为 BST(英国夏令时)。但它在日期结束时给了我 'Z'。它适用于从 UTS 到 IST conversation.Below 是我的代码。

    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

谁知道为什么会这样。代码有任何问题或需要更改某些内容吗?

将日期格式中的 ZZZZZ 替换为 xxxxx。使用 ZZZZZ 将给出 -99:99 除非用户处于 GMT 时区,在这种情况下它只会给出 Zxxxxx 将给出 -99:99 而不管用户的时区。

您可以在Unicode specification.

中查看具体详情

对于 ZZZZZ 它指出:

-08:00
-07:52:58
The ISO8601 extended format with hours, minutes and optional seconds fields. The ISO8601 UTC indicator "Z" is used when local time offset is 0. This is equivalent to the "XXXXX" specifier.

对于 XXXXX 它指出:

-08:00
-07:52:58
Z
The ISO8601 extended format with hours, minutes and optional seconds fields. The ISO8601 UTC indicator "Z" is used when local time offset is 0. (The same as xxxxx, plus "Z".)

对于 xxxxx 它指出:

-08:00
-07:52:58
The ISO8601 extended format with hours, minutes and optional seconds fields. (The same as XXXXX, minus "Z".)