JavaScript显示当前时间的操作

       JavaScript一种直译式脚本语言,是一种动态类型、弱类型、基于原型的语言,内置支持类型。它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本语言,最早是在HTML(标准通用标记语言下的一个应用)网页上使用,用来给HTML网页增加动态功能。Javascript脚本语言同其他语言一样,有它自身的基本数据类型,表达式和算术运算符及程序的基本程序框架。Javascript提供了四种基本的数据类型和两种特殊数据类型用来处理数据和文字。而变量提供存放信息的地方,表达式则可以完成较复杂的信息处理,下面分享一则关于显示当前时间的操作

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
 5 <title>无标题文档</title>
 6 </head>
 7 <script>
 8 function abc(){
 9 var out="";
10 var now =new Date();
11 out+= now.getFullYear();
12 out+="年";
13 out+= (now.getMonth()+1);
14 out+="月";
15 out+= now.getDate();
16 out+="日";
17 out+= now.getHours();
18 out+="时";
19 out+= now.getMinutes();
20 out+="分";
21 document.getElementById("div1").innerHTML=out;
22 }
23 </script>
24 
25 <body onload="abc();">
26 <div id="div1"></div>
27 </body>
28 </html>

  以上为显示当前时间的脚本,如果对你有帮助,希望亲们多多关注setine哦!后续为您带来更精彩的信息。

原文地址:https://www.cnblogs.com/setine/p/6519656.html