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

中文日期解析不了?dayjs('2024年10月17日') #2795

Open
wuwenyuan111 opened this issue Dec 23, 2024 · 2 comments
Open

中文日期解析不了?dayjs('2024年10月17日') #2795

wuwenyuan111 opened this issue Dec 23, 2024 · 2 comments

Comments

@wuwenyuan111
Copy link

Describe the bug
dayjs('2024年10月17日').format('YYYY-MM-DD')
报错:'Invalid Date'

以下的是正常的
dayjs('2024/10/17').format('YYYY-MM-DD')

Expected behavior
dayjs('2024年10月17日').format('YYYY-MM-DD')
能正常解析出来:2024-10-17

Information

  • Day.js Version V1.11.10
  • OS: mac os
  • Browser Chrome 131.0.6778.205
@Beats0
Copy link

Beats0 commented Dec 24, 2024

use customParseFormat

var customParseFormat = require("dayjs/plugin/customParseFormat");
dayjs.extend(customParseFormat);

dayjs('2024年10月17日', 'YYYY-MM-DD').format('YYYY-MM-DD');

@wuwenyuan111
Copy link
Author

这个方法不够通用,按理说,这种中文日期也是高频的存在,应该是能内置解析的。

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