如何在html中获取系统时间

如题所述

<script language="javascript" type="text/javascript">
function getFullStringTime(){
var currentDate = new Date();
var strMinute = currentDate.getMinutes()<10?("0"+currentDate.getMinutes()):currentDate.getMinutes();
var strSecond = currentDate.getSeconds()<10?("0"+currentDate.getSeconds()):currentDate.getSeconds();
with(document){
write("现在时间是:","<br>");
if(currentDate.getDay()==0){
write(currentDate.getYear()+1900,"年",currentDate.getMonth()+1,"月",currentDate.getDate(),"日"," ","星期日"," ",currentDate.getHours(),":",strMinute,":",strSecond);
}else{
write(currentDate.getYear()+1900,"年",currentDate.getMonth()+1,"月",currentDate.getDate(),"日"," ","星期日"," ",currentDate.getHours(),":",strMinute,":",strSecond);
}
}
}

getFullStringTime();

</script>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-08-07
var myDate = new Date();
myDate.getYear(); //获取当前年份(2位)
myDate.getFullYear(); //获取完整的年份(4位,1970-????)
myDate.getMonth(); //获取当前月份(0-11,0代表1月)
myDate.getDate(); //获取当前日(1-31)
myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
第2个回答  推荐于2017-08-14
可以用javascript,在html的head里面写如下代码
<script language="javascript">
var now=new Date();
document.write("今天是"+now.year()+"年"+now.month()+"月"+now.day()+“日”);
</script>本回答被网友采纳
相似回答