Home > Web Front-end > JS Tutorial > javascript get date and week

javascript get date and week

大家讲道理
Release: 2016-11-10 14:32:07
Original
1082 people have browsed it

<!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>
Copy after login

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template