macos - 我可以使用 NSISO8601DateFormatter 解析 ISO-8601 字符串吗?
问题描述
macOS 10.12 中的 Foundation 有一个新类 ,NSISO8601DateFormatter
它声称能够解析 ISO-8601,但我无法理解如何使用它。
它需要 a .formatOptions
,它说它也用于解析。ISO-8601 的全部意义不在于它是一种明确的格式吗?
例如,这有效:
let f = ISO8601DateFormatter()
f.formatOptions = [.withFullDate]
f.date(from: "2018-11-26") // a Date
但这忽略了时间:
let f = ISO8601DateFormatter()
f.formatOptions = [.withFullDate]
f.date(from: "2018-11-26T18:07:13Z") // a Date but wrong
如果我添加.withFullTime
,这可行,但第一个示例失败。
如何使用 NSISO8601DateFormatter 解析 ISO-8601?我需要先自行预解析它以找出它使用的 ISO-8601 的子格式吗?
解决方案
推荐阅读
- three.js - 鼠标移动过快时变换对象不起作用
- p5.js - 在基本 p5js 游戏中添加碰撞和得分
- javascript - Google Chart 上的资源管理器不起作用 - Polymer
- php - 在 renderForm PrestaShop 中显示日期/时间字段
- swift - AVSpeechSynthesiser 窃听 ViewDidLoad 函数
- http - 用户的浏览器似乎每天多次触发请求
- android - 使用 MockWebServer 测试 OkHttp 和使用缓冲区主体测试 MockResponse
- python - 如何在python中获取linux系统变量
- d3.js - 更改geoTIFF文件的投影?
- android - 无法在滚动视图内滚动约束布局