Home > Back-end >  Dynamic time function --> direct call
Dynamic time function --> direct call

Time:11-24

The function fn () {
Var time=new Date ();//get the current time Thu Aug 20, 2020 12:29:26 GMT + 0800 (China standard time)
Var STR="";
Var div=document. GetElementById (" time ");//get to head the head page id is time node
//the console. The log (time);
Var year=time. GetFullYear ();//returns the current vintage 2020
Var mon=time, getMonth () + 1;//return in 0-11 + 1 is returned to the current month
Var day=time. GetDate ();//return day 1-31
Var h=time. GetHours ();//1-24 hours return
Var m=time getMinutes ();//return minutes 1-60
Var s=time. GetSeconds ();//returns the number of seconds to 60
1Var week=time. GetDay (); What day is//returns the current 0 to 6 0 is Sunday

The switch (week) {
Case: 0 week="day";
break;
Case 1: week="a";
break;
Case 2: week="2";
break;
Case 3: week="three";
break;
Case 4: week="four";
break;
Case 5: week="5";
break;
Case 6: week="six";
break;
}
STR=year + "years" + totwo (mon) + "month" + totwo (day) + ", "+" & amp; Have spent" + totwo (h) + ":" + totwo (m) + ":" + totwo (s) + "& amp; Have spent" "+" week + week;
Div. InnerHTML=STR;//to the node assignment so as to realize the dynamic clock
}
  • Related