JS 日期對象

//JS代碼
<!DOCTYPE html>
<html>
<head>
    <title>JS對象</title>
</head>
<body>
<script type="text/javascript">
    var mydate = new Date();//定義一個時間對象
    //返回/設置日期方法
    // get/setDate();
    document.write("日期:"+mydate.getDate()+"<br>");
    // 返回設置年份,四位數表示
    // get/setFullYear()
    document.write("年份:"+mydate.getFullYear()+"<br>");
    // 返回/設置月份方法
    // get/setMonth()
    document.write("月份:"+mydate.getMonth()+"<br>");
    // 返回/設置小時方法
    // get/setHours()
    document.write("小時:"+mydate.getHours()+"<br>");
    // 返回/設置分鐘方法
    // get//setMinutes()
    document.write("分鐘:"+mydate.getMinutes()+"<br>");
    // 返回/設置秒鐘方法
    // get/setSeconds();
    document.write("秒鐘:"+mydate.getSeconds()+"<br>");
    // 返回/設置時間方法
    // get/setTime()
    document.write("時間:"+mydate.getTime()+"<br>");
    mydate.getDay();//返回星期,返回的是0-6的數字,0 表示星期天
</script>
</body>
</html>

這裏寫圖片描述

發佈了91 篇原創文章 · 獲贊 27 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章