Use js to display today's time, year, month, day, including day of the week, js day of the week
<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>
Explanation:
Var datelocalnow = new Date (); create a time class
Var datelocalyear = datelocalnow. getFullYear (); get the 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 hour
Datelocalnow. getMinutes () minutes
Datelocalnow. getSeconds () get seconds
- /**
- * Extended Date: converts Date to a String in the specified format.
- * Month (M), Day (d), 12 hours (h), 24 hours (H), minute (m), second (s), Week (E), quarter (q) can use 1-2 placeholders
- * Year (y) can use 1-4 placeholders, Millisecond (S) can only use 1 placeholder (1-3 digits)
- * Eg:
- * (New Date (). pattern ("yyyy-MM-dd hh: mm: ss. S") => 08:09:04. 423
- * (New Date (). pattern ("yyyy-MM-dd e hh: mm: ss") => 20:09:04
- * (New Date (). pattern ("yyyy-MM-dd EE hh: mm: ss") => 08:09:04 Tuesday
- * (New Date (). pattern ("yyyy-MM-dd EEE hh: mm: ss") => 08:09:04 Tuesday
- * (New Date (). pattern ("yyyy-M-d h: m: s. S") => 2006-7-2. 18
- */