// 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