❶ html时间代码
<script>
var d = new Date();
document.write(d.getHours() +":"+d.getMinutes());
</script>
注:
new Date()是创建一个日期对象,里面包含了年月日时分秒和毫秒
getHours()方法是取得小时数,getMinutes()是取得分钟数
❷ 网页时间代码
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%" class="redfont red"><div align="center">今天是:</div></td>
<td width="78%" class="redfont red"><script language="javascript">
function showTime(){
var oDiv = document.all('oDiv');
var oDate = new Date();
var strTime = oDate.getFullYear() + '年' + eval(oDate.getMonth()+1) + '月' + oDate.getDate() + '日星期' + '日一二三四五六'.substr(oDate.getDay(),1) + '' + oDate.getHours() + ':' + oDate.getMinutes() + ':' + oDate.getSeconds();
oDiv.innerHTML = strTime;
window.setTimeout('showTime()', 1000);
}
window.onload = showTime;
</script>
<div id="oDiv"></div></td>
</tr>
</table>
❸ 日期+时间代码!!!
<script>
function getDate(){
var d = new Date();
var year = d.getYear();
var month = d.getMonth()+1;
var date = d.getDate();
document.write(year+"年"+month+"月"+date+"日");
}
function getTime(){
var t=new Date();
var hour=t.getHours();
var minutie=t.getMinutes();
var second=t.getSeconds();
document.write(hour+"时" +minutie+"分"+second+"秒")
}
getDate();
getTime();
</script>
❹ 求一个时间html代码 格式:年月日时分秒(可以动)
<script language=JavaScript>
var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;}
function startclock () {
stopclock();
showtime();}
function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" +((hours >= 12) ? "下午 " : "上午 " )
timeValue += ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
document.clock.thetime.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;}
</SCRIPT>
<body onload=startclock()>
<form name=clock >
<input name=thetime style="font-size: 9pt;color:#000000;border:0" size=12>
</body>
❺ 关于时间日期的代码。
日期:
年:today.getFullYear();
月:today.getMonth() + 1;
日:today.getDate();
中间分隔符及小于10补0的方法参照你上面的代码搞一下
❻ 时间日期代码
<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
// add a zero in front of numbers<10
m=checkTime(m)
s=checkTime(s)
document.getElementById('txt').innerHTML=h+":"+m+":"+s
t=setTimeout('startTime()',500)
}
function checkTime(i)
{
if (i<10)
{i="0" + i}
return i
}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
</body>
</html>
❼ 过去时间代码
用datediff呀。。。
aa=datediff("d","time1","time2")
这样吧,我写一点你看一下。。
<%time1="2008-4-27"
time2="2008-12-25"
aa=datediff("d",time1,time2)
%>
time1为:<%=time1%><br>
time2为:<%=time2%><br>
中间差值为:<font color="red"><%=aa%>天
自己测试一下。。。
要其它的功能就自己写吧。。。有不明白的可以给我留言。
❽ js时间代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>dateutil-js时间举例</title>
<!-- <script src="http://www.shicishu.com/down/dateutil-1.0.0.js"></script>-->
<script src="http://www.shicishu.com/down/dateutil-1.0.0.min.js"></script>
</head>
<body>
<script type="text/javascript">
console.log(getdate_WMdy_En());//Thurs.Sept.2, 2020
console.log(getdate_yMdhms_T());//2020-9-2 21:41:7
console.log(getdate_WyMdhms_C());//星期四 2020年9月2日 21时38分33秒
</script>
</body>
</html>
❾ 时间代码怎么弄
第一种:
<script language="javascript">
time=new Date();
year=time.getYear();
month=time.getMonth()+1;
day=time.getDate();
with(document){
write("今天是:"+year+"年"+month+"月"+day+"日"+" ")
write('星期'+'日一二三四五六'.charAt(time.getDay()))}
</script>
第二种:
<script>
document.write(new Date().toLocaleDateString()+" 星期"+"日一二三四五六".split("")[new Date().getDay()])
</script>
第三种:
<DIV id=timers>
<SCRIPT language=JavaScript>setInterval("timers.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);</SCRIPT>
</DIV>
第四种:
<script>
/*
Live Date Script-
?Dynamic Drive (www.jpndns.com)
For full source code, installation instructions, 100's more DHTML scripts, and Terms Of Use,
visit http://www.girlmov.com
*/
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours
}
if (hours==0)
hours=00
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate="<small><font color='000000' face='Arial' size=1><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn
+"</b></font></small>"
if (document.all)
document.all.clock.innerHTML=cdate
else
document.write(cdate)
}
if (!document.all)
getthedate()
function goforit(){
if (document.all)
setInterval("getthedate()",1000)
}
window.onload=goforit
</script>
<div id=clock></div>
❿ 标准时间代码
<!-- 在表单中显示当前时间 -->
<!--把以下代码至你的html文件的<body>和</body>之间-->
<script>
<!-- Hide
var timerID = null
var timerRunning = false
function MakeArray(size)
{
this.length = size;
for(var i = 1; i <= size; i++)
{
this[i] = "";
}
return this;
}
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false
}
function showtime () {
var now = new Date();
var year = now.getYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var day = now.getDay();
Day = new MakeArray(7);
Day[0]="SUN";
Day[1]="MON";
Day[2]="TUE";
Day[3]="WED";
Day[4]="THU";
Day[5]="FRI";
Day[6]="SAT";
var timeValue = "";
timeValue += (Day[day]) + " ";
timeValue += ((month < 10) ? " 0" : " ") + month + "-";
timeValue += date + "-" + year + " ";
timeValue += ((hours <= 12) ? hours : hours - 12);
timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
timeValue += (hours < 12) ? " AM" : " PM";
document.jsfrm.face.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true
}
function startclock () {
stopclock();
showtime()
}
//-->
</script>
<BODY onLoad="startclock();">
<FORM NAME='jsfrm'>
<INPUT TYPE=text NAME='face' size=35 value=''>
</form>
补充:
首先要理解客户端和服务器
js是运行在客户端机子上的一种脚本程序,而这个显示时间的代码是获取的客户端主机上的时间,即你浏览一个网页时,上面显示的是你机子的系统时间,你机子的系统时间改变了,那它显示的时间也会随着变化。
而用asp,jsp等动态的网页编程就可以获取服务器的时间,所以当你浏览这种网页时,不管你的机子上是时间怎么变,它都会显示的是远程服务器的时间,这也许就是你理解的“我要的是一个可以显示真正的背景时间的代码,就算你把本机时间改了,这个页面上的时间也不会变的”。
所以用js不能实现的,不过没人用asp,jsp等获取服务器的时间来显示到客户端,当很多人同时浏览时,样对服务器的压力很大,所以基本上看不到有楼主所说的那种情况,因为动态网站里面不会用它