skw*_*wny 3 javascript date momentjs
我正在使用 moment.js 将 ISO 日期/时间/区域字符串转换为本地字符串。根据文档和其他类似的问题,例如this,本来应该非常简单的事情结果却并非如此,并且给了我一些奇怪的输出。这是我所拥有的:
\n\nconsole.log(\'date/time before is: \', date);\n// date/time before is: 2016-12-23T23:10:00.000Z\n\nvar datetime = moment(date).format("dddd, MMMM Do YYYY, h:mm:ss a");\n\nconsole.log(\'date/time after is: \', datetime);\n// date/time after is: p\xc3\xa1tek, prosinec 23. 2016, 3:10:00 pm\nRun Code Online (Sandbox Code Playgroud)\n\n我使用的格式字符串直接来自文档。目的是在它工作后能够按照我需要的方式对其进行格式化。
\n我猜您正在使用 moment-with-locales,因为“p\xc3\xa1tek, prosinec”在捷克语中是“星期五,十二月”的意思。
\n\n我对 moment.js 使用了以下 cdn 链接:
\n\nhttps://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js
\n\n这段代码:
\n\nvar date = new Date().toISOString();\n\nconsole.log(date);\n\nvar datetime = moment(date).format("dddd, MMMM Do YYYY, h:mm:ss a");\n\nconsole.log(datetime);\nRun Code Online (Sandbox Code Playgroud)\n\n并得到了预期的结果。这是一个使用 moment.js 的小提琴,它产生我认为你想要的输出。
\n