23 lines
680 B
JavaScript
23 lines
680 B
JavaScript
/**
|
|
* Datum und Uhrzeit in der Berliner Zeitzone (beruecksichtigt MESZ/MEZ automatisch),
|
|
* fuer Anzeige und Dateinamen. date: 'tt.mm.jjjj', time: 'hhmm' (24h, '0030' statt '2430').
|
|
*/
|
|
export function berlinDateTime(date = new Date()) {
|
|
const parts = new Intl.DateTimeFormat('de-DE', {
|
|
timeZone: 'Europe/Berlin',
|
|
day: '2-digit',
|
|
month: '2-digit',
|
|
year: 'numeric',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
hourCycle: 'h23',
|
|
}).formatToParts(date)
|
|
|
|
const value = (type) => parts.find((part) => part.type === type)?.value
|
|
|
|
return {
|
|
date: `${value('day')}.${value('month')}.${value('year')}`,
|
|
time: `${value('hour')}${value('minute')}`,
|
|
}
|
|
}
|