设计HTML文件时,javascript获取时间
发布网友
发布时间:2022-04-26 05:46
我来回答
共5个回答
热心网友
时间:2022-04-26 07:15
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开始的毫秒数)
myDate.getHours(); //获取当前小时数(0-23)
myDate.getMinutes(); //获取当前分钟数(0-59)
myDate.getSeconds(); //获取当前秒数(0-59)
myDate.getMilliseconds(); //获取当前毫秒数(0-999)
myDate.toLocaleDateString(); //获取当前日期
var mytime=myDate.toLocaleTimeString(); //获取当前时间
myDate.toLocaleString( ); //获取日期与时间
热心网友
时间:2022-04-26 08:33
<script language="JavaScript">
<!--
function tick() {
var hours, minutes, seconds;
var intHours, intMinutes, intSeconds;
var today;
today = new Date();
intHours = today.getHours();
intMinutes = today.getMinutes();
intSeconds = today.getSeconds();
if (intHours == 0) {
hours = "00:";
} else if (intHours < 10) {
hours = "0" + intHours+":";
} else {
hours = intHours + ":";
}
if (intMinutes < 10) {
minutes = "0"+intMinutes+":";
} else {
minutes = intMinutes+":";
}
if (intSeconds < 10) {
seconds = "0"+intSeconds+" ";
} else {
seconds = intSeconds+" ";
}
timeString = hours+minutes+seconds;
Clock.innerHTML = timeString;
window.setTimeout("tick();", 1000);
}
window.onload = tick;
//-->
</script>
<span id="Clock"></span>
热心网友
时间:2022-04-26 10:08
<label id="time"/>
<script language="JavaScript">
window.onload = function(){
var label = document.getElementById("time");
window.setInterval(function(){
var now = new Date(),
y = now.getFullYear(),
month = now.getMonth()+1,
d = now.getDate(),
h = now.getHours(),
m = now.getMinutes(),
s = now.getSeconds(),
SS = now.getMilliseconds(),
time = "当前时间:"+y+"-"+month+"-"+d+" "+h+":"+m+":"+s;
label.innerHTML = time;
},999);
}
</script>
热心网友
时间:2022-04-26 11:59
楼上都说的很好啊...
热心网友
时间:2022-04-26 14:07
<script language=Javascript>
var urodz=new Date(