n0shake/clocker

Date/time format doesn't match system

Closed this issue · 3 comments

Clocker on the left, system clock on the right, note the "15" is in a different place:
Screenshot 2021-02-15 at 09 07 39

@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 :/

Closing as I'm not aware of any way Clocker can derive the time format set in the system clock.

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日(火)
*/