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

month is shifted when parsing from a custom string. #1124

Closed
taimikam99 opened this issue Oct 12, 2020 · 2 comments
Closed

month is shifted when parsing from a custom string. #1124

taimikam99 opened this issue Oct 12, 2020 · 2 comments

Comments

@taimikam99
Copy link

Describe the bug
When parsed from the string to a dayjs instance, the month value is shifted.
スクリーンショット 2020-10-12 13 33 44
Expected behavior

input

var dayjs = require("dayjs")
var customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
console.log(dayjs("1996-02-02", "YYYY-MM-DD").month()); 
console.log(dayjs("1996-05-02", "YYYY-MM-DD").month());

output

2
5

Information

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

iamkun commented Oct 13, 2020

Dayjs use 0 based month the same as the native Date object.

You can use dayjs().format('MM') to get the result you want.

@taimikam99
Copy link
Author

@iamkun
Thank you! I'll try it.

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