javascriptreactjsdate-fnsdate-fns-tz

Date-FNS Timezone Abbreviation


How do I convert the Australian Eastern Daylight Time to just AEST? Currently it outputs like 11/11/2022 15:29:25 Australian Eastern Daylight Time. Expected output would be like 11/11/2022 15:29:25 AEDT

import { formatInTimeZone } from 'date-fns-tz'
import auLocale from 'date-fns/locale/en-AU'

formatInTimeZone(
        new Date(value),
        'Australia/Sydney',
        'dd/MM/yyyy HH:mm:ss zzzz',
        { locale: auLocale }
      )

Solution

  • Use zzz for the format of the timezone instead of zzzz.

    Sample: 'dd/MM/yyyy HH:mm:ss zzzz'