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

Wrong time output #1157

Closed
hanahaneull opened this issue Oct 20, 2020 · 2 comments
Closed

Wrong time output #1157

hanahaneull opened this issue Oct 20, 2020 · 2 comments

Comments

@hanahaneull
Copy link

hanahaneull commented Oct 20, 2020

Describe the bug
Wrong month.
Input

var dayjs = require('dayjs');
let utc = require('dayjs/plugin/utc');
let timezone = require('dayjs/plugin/timezone');

dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.tz.setDefault('Asia/Jakarta');

console.log(dayjs.tz(Date.now()));

Output

d {
  '$L': 'en',
  '$d': 2020-10-20T18:01:44.529Z,
  '$x': { '$localOffset': -420, '$timezone': 'Asia/Jakarta' },
  '$y': 2020,
  '$M': 9,
  '$D': 21,
  '$W': 3,
  '$H': 1,
  '$m': 1,
  '$s': 44,
  '$ms': 529,
  '$offset': 420
}

Expected behavior
The '$M' should be 10 instead of 9
My hard guess is month start from 0. I dont know if this right or wrong. But if right, maybe add feature able to change month start from 1 instead of 0

Information

  • Day.js Version: 1.9.3
  • OS: Manjaro Linux
  • Time zone: GMT +07:00 Asia/Jakarta
@iamkun
Copy link
Owner

iamkun commented Oct 21, 2020

First of all, Dayjs use a 0-indexed month.

Please use the appropriate getter to get the result you want, not using the instance's private variable.

@hanahaneull
Copy link
Author

My bad

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