new Date()时间对象

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>.html</title>
<style>
</style>
<script src="jquery-1.7.2.min.js"></script>
<script>
// getDay()返回一星期中的某一天(0-6)
// getDate()返回一个月中的某一天(1-31)
//在使用switch语句的时候,因为return具有停止执行函数的功能,所以不用加break;

function toChinese(day){
switch(day){
case 0: return "日";
case 1: return "一";
case 2: return "二";
case 3: return "三";
case 4: return "四";
case 5: return "五";
case 6: return "六";
}
}
function getTime(){
var oDate=new Date();
var str="";
str=oDate.getFullYear()+"年"+(oDate.getMonth()+1)+"月"+oDate.getDate()+"日 星期"+toChinese(oDate.getDay());
$(".time").html(str);
}
</script>
</head>
<body>
<button class="timeBtn" onclick="getTime()">北京时间</button>
<div class="time"></div>
</body>
</html>

原文地址:https://www.cnblogs.com/annie211/p/6029756.html