javascript mock calendar

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Document</title>
 6     <style>
 7         div {
 8             width: 800px;
 9             margin: 200px auto;
10             color: orange;
11              text-align : center ; 
12              font : 600 30px/30px "simSun" ; 
13          } 
14      </ style > 
15  </ head > 
16  < body > 
17      < div ></ div > 
18  
19      < script > 
20          // Simulate calendar requirements: open the page every day to display the year, month, day and day of the week 
21          // Steps: Create a date object of the current date, get the year, month, day and week in it, and assign it to div 
22  
23          // 1. Create a current date date object 
24          var date=  new Date();
 25          // 2. Get the year, month, day and week 
26          var year = date.getFullYear();
 27          var month = date.getMonth();
 28          var day = date.getDate();
 29          var week = date.getDay();
 30          // console.log(year+" "+month+" "+day+" "+week); 
31          // 3. Assign to div 
32          var arr = [ " Sunday " , " Week Monday " , " Tuesday" , " Wednesday " , " Thursday " , " Friday " , " Saturday " ];
 33          var div = document.getElementsByTagName( " div " )[ 0 ];
 34          div.innerText =  " Today is: " + year + " year " + (month + 1 ) + " month "+day+""+arr[week];
35     </script>
36 </body>
37 </html>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324551120&siteId=291194637