<html> <body> <script type="text/javascript"> var date = new Date(); date.setFullYear(2017,0,1, 0, 0, 0); document.write("date = " + date + "<br/>"); date.setDate(date.getDate()+5); document.write("after date + 5, date = " + date + "<br/>"); date.setDate(date.getDate()-10); document.write("after date - 10, date = " + date + "<br/>"); </script> </body> </html>
比较Date
<html> <head> <meta charset="UTF8" /> </head> <body> <script type="text/javascript"> var date1 = new Date(); var date2 = new Date(); date1.setTime(Date.UTC(2017,0,1)); date2.setTime(Date.UTC(2016,11,31)); document.write("date1 = " + date1.toLocaleString() + "<br/>"); document.write("date2 = " + date2.toLocaleString() + "<br/>"); document.write("date1 - date2 = " + (date1 - date2) + "毫秒<br/>"); document.write("date1 - date2 = " + (date1 - date2)/1000/60/60 + "小时<br/>"); document.write("date1 > date2 = " + (date1 > date2) + "<br/>"); document.write("date1 < date2 = " + (date1 < date2) + "<br/>"); </script> </body> </html>
以上所述是小编给大家介绍的JavaScript Date 知识浅析,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
您可能感兴趣的文章: