我使用 Materialise Datepicker 选择法语格式的日期。现在我需要将此日期格式化回日期对象,以便我可以在我的 api 中使用它。以下是我尝试将日期转换回正常格式的方法:
moment("dimanche 30 juillet 2017","dddd D MMMM YYYY").locale('fr').toDate();
但我收到无效日期
。有没有办法使用时刻将此日期转换回来?或者我可以以某种方式 Hook materialize 组件来检索正常日期吗?
最佳答案
在尝试解析法国日/月名称之前,您需要设置 fr 区域设置。
moment.locale('fr');
moment("dimanche 30 juillet 2017","dddd D MMMM YYYY").toDate();
关于javascript - 时刻格式详细日期作为日期对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45403107/