• javascript语法之Date对象与小案例


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script type="text/javascript"> 
    /*
    日期对象(Date)
     
     
    */
    	var date = new Date(); //获取到当前的系统时间
    	document.write("年:"+ date.getFullYear()+"<br/>");
    	document.write("月:"+ (date.getMonth()+1)+"<br/>");
    	document.write("日:"+ date.getDate()+"<br/>");
    	
    	document.write("时:"+ date.getHours()+"<br/>");
    	document.write("分:"+ date.getMinutes()+"<br/>");
    	document.write("秒:"+ date.getSeconds()+"<br/>");
    	
    	//xxxx年yy月dd日  hh:mm:ss
    	
    	//document.write("当前时间是:"+date.toLocaleString());
    	document.write("当前时间是:"+date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日 "+
    	date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());
     
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <body>
    	
     
    </body>
    </html>




    案例:时间表。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
     
     
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <body>
    	当前系统时间:<span id="time"></span>
    </body>
     
     
    <script type="text/javascript"> //把script放在后边的原因,保证调用<span style="font-family: Arial, Helvetica, sans-serif;">document.getElementById("time");不会报错。如果放在前面浏览器每解析到time的id就会报错。</span>
    	
    	function getCurrentTime(){
    		//获取到当前的系统时间
    		var date = new Date();
    		//把当前系统时间拼装成我指定的格式。
    		var timeInfo =  date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日 "+
    	date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
    	
    		//找span对象
    		var  spanObj = document.getElementById("time");
    		//设置span标签体的内容
    		spanObj.innerHTML = timeInfo.fontcolor("red");
    	}
     
    	getCurrentTime();
    	
    	//定时方法.
    	window.setInterval("getCurrentTime()",1000); /* setInterval   定时方法,第一个参数要指定调用的代码,第二参数是每                                                隔指定的毫秒数调用指定的代码。*/
    			
     
    </script>
     
     
    </html>
    




  • 相关阅读:
    设计模式学习系列3 观察者模式
    设计模式学习系列2 面向对象的5大原则(转)
    设计模式学习系列1 单例模式
    又见到面试的毕业生
    猎头给我打电话
    DirectX基础学习系列8 渐进网格以及外接体
    directX基础学习系列7 网格(自己创建)
    DirectX 基础学习系列6 字体
    语艺杂谈1 – MAP赋值与插入
    DirectX基础学习系列5 融合技术
  • 原文地址:https://www.cnblogs.com/wanghang/p/6299784.html
Copyright © 2020-2023  润新知