最近看了下js显示日期时间
一、超强方法
<script type="text/javascript" charset="utf-8">
function getDateInfo(){
$("#dateinfo").html(new Date().toLocaleString()+' 星期'+'日一二三四 五六'.charAt(new Date().getDay()));
}
setInterval(getDateInfo,1000);
</script>
二、中规中矩方法
<script type="text/javascript" charset="utf-8">
var now = new Date();
function getCurrentDate(){
var currentDate="";
var year = now.getYear();
currentDate+=year+"年";
var month = now.getMonth()+1;
currentDate+=month+"月";
var day = now.getDate();
currentDate+=day+"日";
return currentDate;
}
function getWeek(){
this.length = getWeek.arguments.length;
for(var i=0; i<this.length; i++){
this[i]=getWeek.arguments[i];
}
}
var cur = getCurrentDate();
document.write(cur);
document.write(" ");
var weeks=new getWeek("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
//此处一定要按照"星期日"到"星期六"的顺序写,要和下面的getDay()方法的返回值对应
document.write(weeks[now.getDay()]);
</script>
js显示日期时间
最新推荐文章于 2021-06-30 11:11:52 发布