Date/time format doesn't match system
Closed this issue · 3 comments
Drarok commented
n0shake commented
@Drarok Do you happen how to retrieve the date format set in the system menubar? Looking at docs and at this Apple Support page isn't much help :/
n0shake commented
Closing as I'm not aware of any way Clocker can derive the time format set in the system clock.
Drarok commented
I think it's just the locale default? This shows my (en_GB
) locale correctly. Not sure why the US one has a comma, though?!
import Foundation
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .none
let date = Date(timeIntervalSinceReferenceDate: 118800)
let localeIdentifiers: [String] = ["en_US", "en_GB", "fr_FR", "ja_JP"]
localeIdentifiers.forEach {
let locale = Locale(identifier: $0)
dateFormatter.locale = locale
dateFormatter.setLocalizedDateFormatFromTemplate("EEEMMMd")
print($0, dateFormatter.string(from: date))
}
/*
$ swift example.swift
en_US Tue, Jan 2
en_GB Tue 2 Jan
fr_FR mar. 2 janv.
ja_JP 1月2日(火)
*/