解释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)
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短