Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moment to dayjs, how to print UTC timezone flag? #1832

Open
stheine opened this issue Mar 15, 2022 · 1 comment
Open

moment to dayjs, how to print UTC timezone flag? #1832

stheine opened this issue Mar 15, 2022 · 1 comment

Comments

@stheine
Copy link

stheine commented Mar 15, 2022

Describe the bug

I'm coming from moment, switching to dayjs and struggle with the display of UTC timestamps. I want the current timestamp in UTC format, including the timezone.
in moment, I called:

const moment = require('moment')
moment.utc().format('HH:mm:ss z')
'14:21:49 UTC'

with dayjs, I call:

const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc.js')
const timezone = require('dayjs/plugin/timezone.js')
const advancedFormat = require('dayjs/plugin/advancedFormat.js')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(advancedFormat)
dayjs.utc().format('HH:mm:ss z')
'14:24:45 GMT+1'

how can I make dayjs not display this z timezone as GMT+1, but instead show UTC?

I found this call:

dayjs.utc().tz('UTC').format('HH:mm:ss z')
'14:26:03 UTC'

but I'd like to find a way to make dayjs in general to work with the UTC timezone, without have to convert every individual timestamp.

Expected behavior

I would like instructions and/or updated documentation to show how to make dayjs show the z timezone as UTC for a utc() timestamp.

Information

  • Day.js Version: 1.10.8
  • OS: Linux
  • Browser: Chrome 99 & nodejs 16.14.0
  • Time zone: UTC
@paule89123
Copy link

I'm in the exact same position. It looks from #1881 like timezone is not currently supported. I'll be sticking with moment until this is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants