You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This one is a weirdo, but very cool.
It is not available on a formatter’s dateFormat directly, instead it exists on the class method dateFormat(fromTemplate:, options:, locale:), and thus on the instance method setLocalizedDateFormatFromTemplate(_:).
Setting the template to j on a formatter will return the hour either in 24-hour time or am/pm depending on the locale.
An example
import Foundation
letformatter=DateFormatter()
formatter.locale =Locale(identifier:"fr")
formatter.setLocalizedDateFormatFromTemplate("j")print(formatter.string(from:Date())) /* -> "19 h" */
/* Same example with a different locale */
formatter.locale =Locale(identifier:"en_US")
formatter.setLocalizedDateFormatFromTemplate("j") /* Must be set again after changing the locale. */
print(formatter.string(from:Date())) /* -> "7 PM" */
The text was updated successfully, but these errors were encountered:
This one is a weirdo, but very cool.
It is not available on a formatter’s
dateFormat
directly, instead it exists on the class methoddateFormat(fromTemplate:, options:, locale:)
, and thus on the instance methodsetLocalizedDateFormatFromTemplate(_:)
.Setting the template to
j
on a formatter will return the hour either in 24-hour time or am/pm depending on the locale.An example
The text was updated successfully, but these errors were encountered: