<span style= "FONT-SIZE:18PX;" >var datelocalweek=new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"), var datelocalnow=new Date (); var datelocalyear=datelocalnow.getfullyear (); var datelocalmonth= (datelocalmonth= "0" + (Datelocalnow.getmonth () +1)). substr (datelocalmonth.length-2,2); var datelocalday= (datelocalday= "0" +datelocalnow.getdate ()). substr (datelocalday.length-2,2); var datelocalweekday=datelocalweek[datelocalnow.getday ()]; document.write ("<font color= #fc7a05 > Beijing time </font><font color= #666666;:" +datelocalyear+ "Year" + datelocalmonth+ "Month" +datelocalday+ "Day" + " " +datelocalnow.gethours () + ":" +datelocalnow.getminutes () + ":" + Datelocalnow.getseconds () + "+datelocalweekday+" </font> "); </span>
Explained below:
var datelocalnow=new Date (); Set up a Time class
var datelocalyear=datelocalnow.getfullyear (); Get year
var datelocalmonth= (datelocalmonth= "0" + (Datelocalnow.getmonth () +1)). substr (datelocalmonth.length-2,2); Get month
var datelocalday= (datelocalday= "0" +datelocalnow.getdate ()). substr (datelocalday.length-2,2); Get Date
var datelocalweekday=datelocalweek[datelocalnow.getday ()]; Get Week
Datelocalnow.gethours () Get hours
Datelocalnow.getminutes () Get minutes
Datelocalnow.getseconds () Get seconds
- /**
- * Extension to date, converts date to a string of the specified format
- * months (m), days (d), 12 hours (h), 24 hours (h), minutes (m), seconds (s), Weeks (E), quarter (q) can be used with 1-2 placeholders
- * Year (y) can use 1-4 placeholders, milliseconds (S) only with 1 placeholders (1-3 digits)
- * Eg:
- * (New Date ()). Pattern ("Yyyy-mm-dd hh:mm:ss. S ") ==> 2006-07-02 08:09:04.423
- * (New Date ()). Pattern ("Yyyy-mm-dd E HH:mm:ss") ==> 2009-03-10 II 20:09:04
- * (New Date ()). Pattern ("Yyyy-mm-dd EE hh:mm:ss") ==> 2009-03-10 Tuesday 08:09:04
- * (New Date ()). Pattern ("Yyyy-mm-dd EEE hh:mm:ss") ==> 2009-03-10 Tuesday 08:09:04
- * (New Date ()). Pattern ("yyyy-m-d h:m:s.s") ==> 2006-7-2 8:9:4.18
- */
Use JS to display today's time, month day, including days of the week