Senseful
Senseful

Reputation: 91691

Which version of UTS-35 does NSDateFormatter use?

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

Answers (1)

Senseful
Senseful

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:

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 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.

Upvotes: 2

Related Questions