js如何改变时间的默认格式

时间:2024-10-11 21:37:39

1、新建一个html文件,命名为test.html,用于讲解js如何改变时间的默认格式。

js如何改变时间的默认格式

2、在script标签内,使用Date()获得当前时间,用于测试。

js如何改变时间的默认格式

3、在script标签内,分别使用getFullYear(),getMonth()和getDate()方法从默认时间中提取出年月日。

js如何改变时间的默认格式

4、在script标签内,将获得的年月日拼装成新的时间格式,使用write方法输出。

js如何改变时间的默认格式

5、在浏览器打开test.html文件,查看结果。

js如何改变时间的默认格式
© 手抄报圈