Use JS to display today's time, month day, including days of the week

Source: Internet
Author: User
Tags getdate

<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


  1. /**      
  2. * Extension to date, converts date to a string of the specified format
  3. * 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
  4. * Year (y) can use 1-4 placeholders, milliseconds (S) only with 1 placeholders (1-3 digits)
  5. * Eg:
  6. * (New Date ()). Pattern ("Yyyy-mm-dd hh:mm:ss. S ") ==> 2006-07-02 08:09:04.423
  7. * (New Date ()). Pattern ("Yyyy-mm-dd E HH:mm:ss") ==> 2009-03-10 II 20:09:04
  8. * (New Date ()). Pattern ("Yyyy-mm-dd EE hh:mm:ss") ==> 2009-03-10 Tuesday 08:09:04
  9. * (New Date ()). Pattern ("Yyyy-mm-dd EEE hh:mm:ss") ==> 2009-03-10 Tuesday 08:09:04
  10. * (New Date ()). Pattern ("yyyy-m-d h:m:s.s") ==> 2006-7-2 8:9:4.18
  11.  */

Use JS to display today's time, month day, including days of the week

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.