赞
踩
方法一: js调用
js
<script type="text/javascript">
function getCurrentDate() {
var now = new Date();
var year = now.getFullYear(); //得到年份
var month = now.getMonth()+1;//得到月份
var date = now.getDate();//得到日期
var day = now.getDay();//得到周几
var week;
var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
week = arr_week[day];
var time = "";
time = "当前时间:" + year + "年" + month + "月" + date + "日" + " " + week;
document.write(time);
}
</script>
测试
<input type="button" id="date_info" value="当前时间" οnclick="geturrentDate();" />
方法二:在body中直接使用
<script>
var now = new Date();
var year = now.getFullYear(); //得到年份
var month = now.getMonth();//得到月份
var date = now.getDate();//得到日期
var day = now.getDay();//得到周几
var week;
var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
week = arr_week[day];
var time = "";
time = "当前时间:" + year + "年" + month + "月" + date + "日" + " " + week;
document.write(time);
}
</script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。