在javascript中定义Date.parse的格式 [英] Define format for Date.parse in javascript

查看:65
本文介绍了在javascript中定义Date.parse的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Date.parse将字符串转换为javascript中的日期,但是,如果字符串看起来像'10 / 11/2016'那么它被解释为2016年10月11日,我需要它被解释为11月2016年10月

I am using Date.parse to convert a string to a date in javascript, however, if the string looks like this '10/11/2016' it is interpreted as Oct 11 2016, i need it to be interpreted as Nov 10 2016

建议?

推荐答案

默认 Date.parse 在此格式中考虑之前 MM / DD / YYYY 不是你想要的 DD / MM / YYYY

By default Date.parse consider in this format that month precede the day to be in your case MM/DD/YYYY not as you want DD/MM/YYYY.

我更喜欢/建议使用第三方日期解析器库作为 Moment.js

I prefer/suggest using 3rd party date parser library as Moment.js

它可以用你的日期字符串格式是这样的:

It can take your date-string and the format to be like this:

moment("10/11/2016", "DD-MM-YYYY");

这篇关于在javascript中定义Date.parse的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆