• Date对象


    设置日期的几种格式:

    new Date("May 25,2016");

    new Date("2016/9/10,12:20:33");

    new Date(2016,9,10);

    当前系统时间:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>当前系统时间</title>
    </head>
    <body>
    	<div>当前时间:<span id="show"></span></div>
    	<script>
    		setInterval(function() {
    			var date = new Date();
    			var show = document.getElementById('show');
    			var week = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
    			//判断数字,数字小于10显示两位数字效果
    			function checkTime(i) {
    				if (i < 10) {
    					i = '0' + i;
    				}
    				return i;
    			}
    			for (var i = 0; i < week.length; i++) {
    				if (date.getDay() == i) {
    					show.innerHTML = week[i] + date.getFullYear() + '年' +  checkTime((date.getMonth() + 1)) + '月' +  checkTime(date.getDate()) + '日' + checkTime(date.getHours()) + '时' + checkTime(date.getMinutes()) + '分' + checkTime(date.getSeconds()) + '秒' + date.getMilliseconds() + '毫秒';
    				}
    			}
    		}, 1);
    	</script>
    </body>
    </html>
    

      

  • 相关阅读:
    leetcode Remove Linked List Elements
    leetcode Word Pattern
    leetcode Isomorphic Strings
    leetcode Valid Parentheses
    leetcode Remove Nth Node From End of List
    leetcode Contains Duplicate II
    leetcode Rectangle Area
    leetcode Length of Last Word
    leetcode Valid Sudoku
    leetcode Reverse Bits
  • 原文地址:https://www.cnblogs.com/handsomehan/p/5859604.html
Copyright © 2020-2023  润新知