Home  >  Article  >  Web Front-end  >  javascript get date and week

javascript get date and week

大家讲道理
大家讲道理Original
2016-11-10 14:32:071002browse

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>TT</title>
  <script src="jquery.js"></script>
</head>
<body>
<p style="line-height: 50%;"><span></span></p>
<input type="button" value="轻轻" onclick="syncTime()">
<script>
    function syncTime(){
       var mydate = new Date();
       var week;
       switch (mydate.getDay()){
       case 1: week="星期一"; break;
       case 2: week="星期二"; break;
       case 3: week="星期三"; break;
       case 4: week="星期四"; break;
       case 5: week="星期五"; break;
       case 6: week="星期六"; break;
       default: week="星期天";
       }
       var str = "" + mydate.getFullYear() + " 年 " + (mydate.getMonth() + 1) + " 月 " + mydate.getDate() + " 日 " + week;
       $(&#39;.todaytime&#39;)[0].innerHTML = str;
       str = &#39;"savesynctime" : "&#39; + str + &#39;"&#39;
       return str;
    }
    console.log(syncTime());
</script>
</body>
</html>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn