如何使用JavaScript将日期设置为1/1/0001 [英] How to set Date to 1/1/0001 using javascript

查看:72
本文介绍了如何使用JavaScript将日期设置为1/1/0001的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了新的Date(1、0、1),但得到1/1/1901。

I write new Date(1, 0, 1), but get 1/1/1901.

新日期(1001,0,1)获得预期值的1/1/1001。

While new Date(1001,0,1) get 1/1/1001 as expected.

如何在公元1000年之前设置日期

How to set date when the year is before 1000 A.D.

推荐答案

您不能创建 Date 使用年,月,日(和可选的时间参数)构造函数,年份在0–99范围内,因为这些年份映射到1900–1999(请参见 MDN文档)。但是,您可以使用字符串构造 Date 对象:

You can't create a Date using the year, month, day (and optional time parameters) constructor with year in the range 0–99, because those years map to 1900–1999 (see the MDN documentation). However you can construct a Date object using a string:

new Date('0001-01-01')

由于这仅适用于0–99年,因此您可以在公元1000年罚款之前建造以后的年份:

Since this only applies to the years 0–99, you can construct later years before 1000 AD fine:

new Date(900, 0, 1)

这篇关于如何使用JavaScript将日期设置为1/1/0001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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