首頁  >  文章  >  web前端  >  javascript 取得日期和星期

javascript 取得日期和星期

大家讲道理
大家讲道理原創
2016-11-10 14:32:071050瀏覽

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn