ios - 来自字符串时区的日期不使用 DateFormatter
<p><p>代码:</p>
<pre><code>let isoDate = "1981-02-20T10:44:00+0800"
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone.current
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
var localTimeZoneAbbreviation: String { return TimeZone.current.abbreviation() ?? "" }
let date = dateFormatter.date(from: isoDate)!
dateFormatter.string(from: date)
</code></pre>
<p>输出:
<a href="/image/18Yjm.png" rel="noreferrer noopener nofollow"><img src="/image/18Yjm.png" alt="enter image description here"/></a> </p>
<p>为什么日期输出时区是 +07:30 而不是日期字符串和 TimeZone.current 中定义的 +0800?谁能解释一下?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>时区格式不是<code>Z</code>而是<code>ZZZ</code></p>
<pre><code>dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZ"
</code></pre></p>
<p style="font-size: 20px;">关于ios - 来自字符串时区的日期不使用 DateFormatter,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/45584841/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/45584841/
</a>
</p>
页:
[1]