通过new Date()将当前时间信息赋值给变量,然后通过各种get...方法取得具体时间日期
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>document</title> </head> <body> <script> var today = new Date(); console.log(today.getFullYear() + '年'); var month = ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月']; console.log(month[today.getMonth()]); console.log(today.getDay()+'号'); console.log(today.getHours()+'点'); console.log(today.getMinutes() + '分'); console.log(today.getSeconds() + '秒'); </script> </body> </html>