Reputation: 91691
I want to use the dateFormat
parameter on NSDateFormatter (or DateFormatter in Swift) to format dates with a string template such as yyyy-MM-dd
. I realize this comes from UTS-35, but I'm not sure which version of the standard my OS is using.
There used to be a page that specifies exactly which version of the Unicode Technical Standard #35 each version of iOS supports. I can no longer find that page in Apple's documentation.
Which version of UTS-35 do the latest few iOS versions use?
Search keywords: date time format apple nsdate
Upvotes: 1
Views: 360
Reputation: 91691
The Date Formatting Guide has the page I was looking for:
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:
- OS X v10.9 and iOS 7 use version tr35-31.
- OS X v10.8 and iOS 6 use version tr35-25.
- iOS 5 uses version tr35-19.
- OS X v10.7 and iOS 4.3 use version tr35-17.
- iOS 4.0, iOS 4.1, and iOS 4.2 use version tr35-15.
- iOS 3.2 uses version tr35-12.
- OS X v10.6, iOS 3.0, and iOS 3.1 use version tr35-10.
- OS X v10.5 uses version tr35-6.
- OS X v10.4 uses version tr35-4.
So you're most likely looking for version tr35-31 for any of the latest iOS versions.
However, as the dateFormat
documentation states, if you're displaying a date to the user, you're better off avoiding the dateFormat
parameter altogether and using dateStyle
and timeStyle
which take into account the user's 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
andtimeStyle
properties, or thesetLocalizedDateFormatFromTemplate:
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.
Upvotes: 2