// Output the computer system's year, month, day, week, and time

Source: Internet
Author: User
// Output the computer system's year, month, day, week, and time var nowdate = new date (); var year = nowdate. getfullyear (); var day = nowdate. getdate () <10? "0" + nowdate. getdate (): nowdate. getdate (); var hours = nowdate. gethours () <10? "0" + nowdate. gethours (): nowdate. gethours (); var minutes = nowdate. getminutes () <10? "0" + nowdate. getminutes (): nowdate. getminutes (); var today = new date (); // a method of the date and time object getday (), used to obtain the week value of the current system (0-6) 0 indicates Sunday var week = today. getday (); // based on different values of week, the output result is switch (week) {Case 1: Str = "1"; break; Case 2: Str = "2 "; break; Case 3: Str = "3"; break; Case 4: Str = "4"; break; Case 5: Str = "5"; break; Case 6: STR = "6"; break; default: Str = "Sunday";} var STR = "Today is a week" + STR; vaR datestr = year + "-" + month + "-" + day + "" + hours + ":" + minutes + "" + STR +; document. write (datestr );

Explanation:

1. var month = nowdate. getmonth () + 1 <10? "0" + (nowdate. getmonth () + 1): nowdate. getmonth () + 1; // If the month is smaller than 10, a condition is given. That is, when the month is a single digit, a value of 0 is added before it. + 1 is because the month retrieved in Javascript now is 1 less than the actual month, and 1 must be added in actual use.

2. One method for creating a date and time object is getday (), which is used to obtain the week value (0-6) of the current system. 0 represents Sunday. Monday, two, three, four, five, six, and day in the computer are represented by (0-6.

This article is from the "UI master" blog, please be sure to keep this source http://475281641.blog.51cto.com/11320682/1775565

// Output the computer system's year, month, day, week, and time

Related Article

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.