解释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)
热门推荐
9 七十年祝福语简短
10 希望老人健康祝福语简短
11 艺校元旦祝福语大全简短
12 岁月有芬芳祝福语简短
13 寿宴祝福语蛋糕文案简短
14 媳妇生日简短祝福语朋友
15 圣诞祝福语简短贺卡英文
16 公司年会祝福语简短最好
17 哈尼族祝福语简短
18 默克尔离职祝福语简短