-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Description
Currently the DateTimeFormat
that is created uses en-US
as the locale. However this is not sufficent to include the desired timezone name.
dayjs/src/plugin/timezone/index.js
Lines 15 to 34 in 1d8746c
const getDateTimeFormat = (timezone, options = {}) => { | |
const timeZoneName = options.timeZoneName || 'short' | |
const key = `${timezone}|${timeZoneName}` | |
let dtf = dtfCache[key] | |
if (!dtf) { | |
dtf = new Intl.DateTimeFormat('en-US', { | |
hour12: false, | |
timeZone: timezone, | |
year: 'numeric', | |
month: '2-digit', | |
day: '2-digit', | |
hour: '2-digit', | |
minute: '2-digit', | |
second: '2-digit', | |
timeZoneName | |
}) | |
dtfCache[key] = dtf | |
} | |
return dtf | |
} |
For example:
getDateTimeFormat('Australia/Sydney').format(new Date())
// '09/15/2025, 09:39:52 GMT+10'
whereas if it was switched to en-AU
we get the following
getDateTimeFormat('Australia/Sydney').format(new Date())
// '15/09/2025, 09:39:52 AEST'
Notice that with en-US
the timezone is GMT+10
but with en-AU
it is AEST
.
I would like to request a change such that the dayjs.locale
set by imports like import 'dayjs/locale/en-au'
is also used when constructing the DateTimeFormat
.
Metadata
Metadata
Assignees
Labels
No labels