Use js to display today's time, year, month, day, including day of the week, js day of the week

Source: Internet
Author: User

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


  1. /**
  2. * Extended Date: converts Date to a String in the specified format.
  3. * Month (M), Day (d), 12 hours (h), 24 hours (H), minute (m), second (s), Week (E), quarter (q) can use 1-2 placeholders
  4. * Year (y) can use 1-4 placeholders, Millisecond (S) can only use 1 placeholder (1-3 digits)
  5. * Eg:
  6. * (New Date (). pattern ("yyyy-MM-dd hh: mm: ss. S") => 08:09:04. 423
  7. * (New Date (). pattern ("yyyy-MM-dd e hh: mm: ss") => 20:09:04
  8. * (New Date (). pattern ("yyyy-MM-dd EE hh: mm: ss") => 08:09:04 Tuesday
  9. * (New Date (). pattern ("yyyy-MM-dd EEE hh: mm: ss") => 08:09:04 Tuesday
  10. * (New Date (). pattern ("yyyy-M-d h: m: s. S") => 2006-7-2. 18
  11. */

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.