This code is compiled from W3school:http://www.w3school.com.cn
1. Get the current date:
document.write ("Current time:" +new Date ());
2. Get timestamp (milliseconds):
document.write (New Date (). GetTime ());
3. Set Date (year is required, month day is optional):
var d = new Date (); D.setfullyear (2012,3,16) document.write (d); document.write ("<br/>"); document.write (D.gettime ());
4. Return the current day of the week:
document.write (New Date (). GetDay ())
5. Comparison of date objects:
function Comparedate () { var oneday = new Date (); Oneday.setfullyear (2015,2,26); var currentday = new Date (); if (oneday<currentday) { alert ("before"); } else{ alert ("after"); } }
:
Example code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Javascript: Basic usage of date objects (dates)