新日期(“ YYYY / MM”)在IE 11上不起作用 [英] new Date("YYYY/MM") not work on IE 11

查看:58
本文介绍了新日期(“ YYYY / MM”)在IE 11上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我使用下面的js代码以仅输入日期的年份和月份作为日期:

In my project, i use js code below to take date with date input only year and month:

var current_time = new Date(current); 

使用当前数据是这样的: 2017/04
chrome,但在IE 11上,我获得的current_time无效日期。你们可以帮忙在IE上获取只有年份和月份的日期表单数据吗?谢谢。

with current data is something like this: "2017/04" It work perfect on chrome but on IE 11, i get invalid date for current_time. Can your guys help to to take date form data which only has year and month like this on IE? Thankyou.

推荐答案

日期应按照 RFC 2822 ISO 8601 因此,如果您使用'-'而不是'/,它将在任何地方工作。

Dates should be formatted according RFC 2822 or ISO 8601 So if you use '-' instead of '/ it will work every where.

console.log(new Date("2017-04"))

如果您仍然想用'/'作为约会日期

if you want to still have your date with '/' you can do this

console.log(new Date("2017/04".replace(/\//g, "-")));

这篇关于新日期(“ YYYY / MM”)在IE 11上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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