NSDateFormatter 使用哪个版本的 UTS-35?

Which version of UTS-35 does NSDateFormatter use?

我想在 NSDateFormatter(或 Swift 中的 DateFormatter)上使用 dateFormat 参数来使用 yyyy-MM-dd 等字符串模板格式化日期。我意识到这来自 UTS-35,但我不确定我的 OS 使用的是哪个版本的标准。

曾经有一个页面明确指定 Unicode Technical Standard #35 每个版本 iOS 支持哪个版本。我再也找不到 Apple 文档中的那个页面了。

最新的几个 iOS 版本使用哪个版本的 UTS-35?

搜索关键词:日期时间格式apple nsdate

Date Formatting Guide 有我要找的页面:

Fixed Formats

To specify a custom fixed format for a date formatter, you use setDateFormat:. The format string uses the format patterns from the Unicode Technical Standard #35. The version of the standard varies with release of the operating system:

所以您很可能正在寻找 version tr35-31 以获取任何最新的 iOS 版本。

但是,如 dateFormat documentation 所述,如果您要向用户显示日期,最好完全避免使用 dateFormat 参数并使用 dateStyletimeStyle 考虑到用户的 locale/preferences.

You should only set this property when working with fixed format representations, as discussed in Working With Fixed Format Date Representations. For user-visible representations, you should use the dateStyle and timeStyle properties, or the setLocalizedDateFormatFromTemplate: method if your desired format cannot be achieved using the predefined styles; both of these properties and this method provide a localized date representation appropriate for display to the user.