您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關如何在html中使用JavaScript獲取系統當前時間,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
具體內容如下
<html> <head> <STYLE> TD { FONT-SIZE: 12px; COLOR: #ffffff; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif } </STYLE> <SCRIPT language=JavaScript> function tick() { var years,months,days,hours, minutes, seconds; var intYears,intMonths,intDays,intHours, intMinutes, intSeconds; var today; today = new Date(); //系統當前時間 intYears = today.getFullYear(); //得到年份,getFullYear()比getYear()更普適 intMonths = today.getMonth() + 1; //得到月份,要加1 intDays = today.getDate(); //得到日期 intHours = today.getHours(); //得到小時 intMinutes = today.getMinutes(); //得到分鐘 intSeconds = today.getSeconds(); //得到秒鐘 years = intYears + "-"; if(intMonths < 10 ){ months = "0" + intMonths +"-"; } else { months = intMonths +"-"; } if(intDays < 10 ){ days = "0" + intDays +" "; } else { days = intDays + " "; } 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 = years+months+days+hours+minutes+seconds; Clock.innerHTML = timeString; window.setTimeout("tick();", 1000); } window.onload = tick; </SCRIPT> </head> <BODY leftMargin=0 topMargin=0 marginwidth="0" marginheight="0"> <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0> <TR bgColor=#73a3d4 height=40> <TD noWrap align=right width=209 ><SPAN id="Clock"></SPAN></TD> </TR> </TABLE> </BODY> </HTML>
以上就是如何在html中使用JavaScript獲取系統當前時間,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。