解释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 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短