JavaSCript? ?? ??
Date ??
Date ??? String ??? ????. ???? String ??? ??? ? ????. ? ??? ????? ?????.
Date ??? new ???? ???? ???? ??, ??? ??? Date ??? ??? ???? ??? ? ????.
Date ?? ?? ??
(1) ???? ?? ??(??) ?? ??? ????? ?????.
var today = new Date();
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //創(chuàng)建現(xiàn)在的日期時(shí)間對(duì)象實(shí)例 //today就是剛創(chuàng)建的Date對(duì)象實(shí)例 var today=new Date(); document.write(today); </script> </head> <body> </body> </html>
(2) ??? ?????? ?? ?? ?? ????? ????, ????? ????????.
?? ???: 1970? 1? 1? 0:00:00? ?? ?? ?? ??? ???(1? = 1000???)? ?????.
var ??? = new Date(10000); //??? 1970? 1? 1? 0:00:10
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //指定毫秒值 var time=new Date(20000); document.write(time); </script> </head> <body> </body> </html>
(3) ??? Time? ??? ?????. ??, ????? ?? ? ?? ??????.
var ??? = new Date(“2016/11/11 10:00:00”);
?: ?? ?? ??? ????
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //計(jì)算你今年多大了 //1.創(chuàng)建現(xiàn)在的日期對(duì)象,取出當(dāng)前的毫秒值 var now = new Date(); var nowTime = now.getTime(); //2.創(chuàng)建出生日期時(shí)的日期對(duì)象,取出那時(shí)的毫秒值 var ago = new Date("1992/10/10"); var agoTime = ago.getTime(); //3.兩個(gè)毫秒相減 var str=(nowTime-agoTime)/1000/3600/24/365; document.write("你今年"+str+"歲了") </script> </head> <body> </body> </html>
(4) ?? ?? ???? ??
var ??? = new Date(2015+100,4,25,10,20,0) // ??? ??, ?, ?, ?, ?, ????. ??, ?, ?? ?????.
?: 100??? ?? ??? ??? ???.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //計(jì)算你今年多大了 //1.創(chuàng)建現(xiàn)在的日期對(duì)象,取出當(dāng)前的毫秒值 var now = new Date(); var nowTime = now.getTime(); //2.創(chuàng)建未來日期時(shí)的日期對(duì)象,取出那時(shí)的毫秒值 var future = new Date(1992+100,10,10); var futureTime = future.getTime(); //3.兩個(gè)毫秒相減 var str=(futureTime-nowTime)/1000/3600/24; document.write("你還要活"+str+"天,才能到100歲"); </script> </head> <body> </body> </html>
getFullYear(): 4?? ??? ?????.
getMonth(): ?? ?????. ?? 0-11???.
getDate(): 1~31? ?? ?? ?????.
getHours(): ??? ?????.
getMinutes(): ?
getSeconds(): ?
getMilliseconds( ) ???
getDay() weekday
getTime() ??? ?, 1970? 1? 1??? ????? ??? ?