<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <!--内置对象---时间 创建日期对象: new Date()创建当前日期对象--> </head> <body> <script> //定义取当前时间对象 let date=new Date() document.write("当前时间是:"+date+"<br/>") //去年,getFullear document.write("当前年是:"+date.getFullYear()+"<br/>") //取月,getMonth,要加1 document.write("当前月是:"+(date.getMonth()+1)+"<br/>") //0-6 0表示的是周日,1-6表示周一到周六,不是哪一天 document.write("当前星期几是:"+date.getDay()+"<br/>") //转换成本地时间 document.write("当前时间是:"+date.toLocaleString()+"<br/>")//当前时间是:2021/11/1 下午12:18:17 document.write("当前时间是:"+date.toLocaleTimeString()+"<br/>")//当前时间是:下午12:18:56 document.write("当前时间是:"+date.toLocaleDateString()+"<br/>")//当前时间是:2021/11/1 document.write("当前时间是:"+date.getTime()+"<br/>")//得到毫秒数(从1970年开始) </script> </body> </html>
内置时间对象Date
最新推荐文章于 2024-05-18 11:09:56 发布