返回一个正常人能看懂的时间

	function formatDate(now) {
		now = new Date(now * 1000);       //函数内*1000    
		var year = now.getFullYear(),
			month = now.getMonth() + 1,
			date = now.getDate(),
			hour = now.getHours(),
			minute = now.getMinutes(),
			second = now.getSeconds();
		minute = checkTime(minute);
		month = checkTime(month);
		date = checkTime(date);
		hour = checkTime(hour);
		second = checkTime(second);
		return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
	}

	function checkTime(i) {
		if(i < 10) {
			i = "0" + i
		}
		return i
	}
	//当前时间豪秒数
	console.log(new Date().valueOf());           //1521090236372 
	 //函数内已经*1000了,所以传值的时候先/1000,依照与后台约定而定
	console.log(formatDate(new Date().valueOf() / 1000));        // 2018-03-15 13:03:56

你可能感兴趣的:(javascript武器库)