The Date object provides three methods:
1. Obtain the current time and date from the system;
2. Set the time and date;
3. Time, date converted into other formats.
Setyear Set the current year
Setmonth Set the current month
Setdate Set the current date
Setday sets the number of weeks for the current object
Sethours set the current hour
Setminutes set the current minute
Setseconds Set the current second
SetTime set current time in milliseconds
<textarea id="runcode20409"><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title> built-in to ext--date</title> </pead> <body> <script language=" JavaScript ">//Get current date from system var now=new date (); document.write ("is Now" +now.getyear () + "year" + (Now.getmonth () +1) + "month" +now.getdate () + "Day" +now.gethours () + "time" + Now.getminutes () + "Min" +now.getseconds () + "seconds" + "");/month is calculated from 0 to 11, so +1. Set Date var now=new date (); Now.setyear (1986); Now.setmonth (10); Now.setdate (06); document.write ("Birth date is" +now.getyear () + "year" + (Now.getmonth () +1) + "month" +now.getdate () + "Day" + ""); Convert date format var now=new date (); document.write (now.togmtstring () + "")//Convert to GMT Format date document.write (now.tolocalestring () + ""),//Convert cost format date </ script> </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Show Current Date:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title> show Current time </title> </pead> <body> <script language=" JavaScript "& Gt var objdate=new Date (); The Var year=objdate.getfullyear ()///definition displays a four-digit number of years. The Var month=objdate.getmonth () +1;//month is calculated from 0, so add one. var date=objdate.getdate (); var day=objdate.getday (); var hours=objdate.gethours (); var minutes=objdate.getminutes (); var seconds=objdate.getseconds (); Switch (day) {case 0:day= "Sunday"; Break Case 1:day= "Monday"; Break Case 2:day= "Tuesday"; Break Case 3:day= "Wednesday"; Break Case 4:day= "Thursday"; Break Case 5:day= "Friday"; Break Case 6:day= "Saturday"; Break document.write ("Today is" +year+ "year" +month+ "month" +date+ "Day" + "," +hours+ ":" +minutes+ ":" +seconds+ "," +day+ ""); </script> </body>;/html>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]