iamkun / iamkun/dayjs

moment to dayjs, how to print UTC timezone flag?

Open
#1,832 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**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`

Contributor guide

Open the contributing guide

Research direction

Start with the utc, timezone, and advancedFormat plugin usage shown in the issue, then check the related Day.js formatting and timezone documentation. Confirm how `z` behaves for `dayjs.utc()` and document the supported way to display `UTC`, including whether converting with `.tz('UTC')` is required; done means the documented behavior answers the reported example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.