如何在html中获取系统时间
答案:3 悬赏:0 手机版
解决时间 2021-03-07 12:53
- 提问者网友:萌卜娃娃
- 2021-03-06 23:11
如何在html中获取系统时间
最佳答案
- 五星知识达人网友:从此江山别
- 2021-03-06 23:30
可以用javascript,在html的head里面写如下代码
<script language="javascript">
var now=new Date();
document.write("今天是"+now.year()+"年"+now.month()+"月"+now.day()+“日”);
</script>
<script language="javascript">
var now=new Date();
document.write("今天是"+now.year()+"年"+now.month()+"月"+now.day()+“日”);
</script>
全部回答
- 1楼网友:何以畏孤独
- 2021-03-07 02:14
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楼网友:时间的尘埃
- 2021-03-07 01:04
<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>
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯