當前位置:首頁 » 股票資訊 » 時間代碼
擴展閱讀
股票基金信託理財保險 2025-07-12 23:44:03
股票進出資金怎麼看 2025-07-12 23:24:38
美股現在適合買股票嗎 2025-07-12 23:04:25

時間代碼

發布時間: 2021-11-06 16:42:50

❶ 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等獲取伺服器的時間來顯示到客戶端,當很多人同時瀏覽時,樣對伺服器的壓力很大,所以基本上看不到有樓主所說的那種情況,因為動態網站裡面不會用它