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

Day return is incorrect with format #703

Closed
dalenguyen opened this issue Oct 21, 2019 · 2 comments
Closed

Day return is incorrect with format #703

dalenguyen opened this issue Oct 21, 2019 · 2 comments

Comments

@dalenguyen
Copy link

Describe the bug
A clear and concise description of what the bug is.

I'm trying to convert a date to a readable format.

For example:

var dayjs = require('dayjs')

const date = '1989-08-12T01:00:00.000Z'
console.log(dayjs(date).format('DD/MM/YYYY'))

The result shows: 11/08/1989

Expected behavior
A clear and concise description of what you expected to happen.

I expect that the log should return 12/08/1989 instead of 11/08/1989

Not sure if I miss any parameters or not. Thanks,

Information

  • Day.js Version [e.g. v1.0.0]: v1.8.16
  • OS: [e.g. iOS]: MacOS
  • Browser [e.g. chrome 62]
  • Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]
@iamkun
Copy link
Owner

iamkun commented Oct 22, 2019

Dayjs will parse date to local time by default.

If you want to get time in utc, please use dayjs.utc

var dayjs = require("dayjs")
var utc = require("dayjs/plugin/utc")
dayjs.extend(utc)
const date = '1989-08-12T01:00:00.000Z'
console.log(dayjs(date).format()) // "1989-08-12T10:00:00+09:00"

const date2 = '1989-08-12T01:00:00.000Z'
console.log(dayjs.utc(date2).format()) "1989-08-12T01:00:00Z"

@dalenguyen
Copy link
Author

Thanks @iamkun. And this is for TypeScript usage

import * as dayjs from 'dayjs'
import * as utc from 'dayjs/plugin/utc'
dayjs.extend(utc)

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