如果dateString没有年份部分,则为Date中的默认年份 [英] Default year in Date if dateString does not have year part

查看:111
本文介绍了如果dateString没有年份部分,则为Date中的默认年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检查如果发送部分值会返回什么值。

I was trying to check what values would return if partial values are sent.

var d = new Date("11/28");
console.log(d.toLocaleDateString())

我期望它是 2016年11月28日(本年),但返回 2001年11月28日

所以问题是为什么将 2001 视为默认年份

So the question is Why is 2001 considered as default year?

推荐答案

2001不被视为默认年份。
这是一个Chrome问题,如果您使用Firefox运行相同的代码,则会得到无效日期

2001 is not consider as default year. This is a Chrome issue, if you run the same code with Firefox you get Invalid Date.

这篇关于如果dateString没有年份部分,则为Date中的默认年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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