abstrakt:3.3 javaScript中 獲取日期對象:日期對象是用以處理日期和時間的(全部都是駝峰寫法?。。。┍仨毾全@取時間才可以獲取年月日時分秒?。。?獲取當前時間 Date() :var myday=new Date() //創(chuàng)建時間對象 獲取年份 getFullYear() :document.write(myday.getFullYear()+"年") 獲取月
3.3 javaScript中 獲取日期對象:日期對象是用以處理日期和時間的
(全部都是駝峰寫法?。。。┍仨毾全@取時間才可以獲取年月日時分秒!?。?/p>
獲取當前時間 Date() :var myday=new Date() //創(chuàng)建時間對象
獲取年份 getFullYear() :document.write(myday.getFullYear()+"年")
獲取月份 getMonth() 0代表的是1月,11代表的是12月:document.write(myday.getMonth()+"月") 可以利用數組來正常顯示月份!
獲取星期 getDay() 0代表的是周日,6代表是周六(返回值是0~6之間的一個整數):document.write("今天是星期"+myday.getDay())
獲取日期 getDate() (返回值是0~31之間的一個整數):document.write("今天是這個月的第"+myday.getDate()+'天')
獲取小時 getHours() (返回值是0~23之間的一個整數):document.write("現在是"+myday.getHours()+"時")
獲取分鐘 getMinutes() (返回值是0~59之間的一個整數):document.write(myday.getMinutes()+"分")
獲取秒鐘 getSeconds() (返回值是0~59之間的一個整數):獲取秒鐘 getSeconds()(返回值是0~59之間的一個整數)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>獲取當前時間</title> <script> function day(){ var myday=new Date() document.write(myday.getFullYear()+"年") document.write(myday.getMonth()+1+"月") document.write(myday.getDate()+"日") document.write(myday.getHours()+"時") document.write(myday.getMinutes()+"分") document.write(myday.getSeconds()+"秒") } </script> </head> <body> <button onclick="day()">獲取當前時間</button> </body> </html>
Korrigierender Lehrer:天蓬老師Korrekturzeit:2019-01-01 18:24:23
Zusammenfassung des Lehrers:Date()?中有非常多的方法,可以對時間和日期進行處理, 要注意中英文之間的習慣