解释JavaScript中的Date()对象?
日期()
Date()方法提供当前日期,此外,使用该Date()方法,我们可以获取指定时间格式的日期。
例
<html> <body> <script> var d = new Date(); document.write(d); </script> </body> </html>
输出结果
Thu May 16 2019 05:29:15 GMT+0530 (India Standard Time)
在其中使用newDate()和7个数字,即使是毫秒也可以得到日期。
示例
<html> <body> <script> var d = new Date(2019, 9, 19, 5, 33, 30, 0); document.write(d); </script> </body> </html>
输出结果
Sat Oct 19 2019 05:33:30 GMT+0530 (India Standard Time)
在上面的示例中,我们在日期中用单行给出了年,月,日,小时,分钟,秒,毫秒等。
我们也只能以指定的格式获取时间,例如只有年,月和日的时间为
示例
<html> <body> <script> var d = new Date(2019, 9, 19); document.write(d); </script> </body> </html>
输出结果
Sat Oct 19 2019 00:00:00 GMT+0530 (India Standard Time)
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短