javascript学习笔记 4

今天收获很多,学习了Date,和Function的然后按照,昨天的计划,做了个时钟,先把Date部分的代码贴出来


/*============================================================================
#     FileName: ex7.js
#         Desc: 
#       Author: baobaoyeye
#        Email: bao.renyi@gmail.com
#     HomePage: http://karloo.com http://blog.csdn.net/baobaoyeye
#      Version: 0.0.1
#   LastChange: 2011-07-26 08:29:43
#      History:
#===========================================================================*/

function fun1(){
	var d1 = new Date();

	var d2 = new Date(Date.parse("6/13/2001"));
	var d3 = new Date("6/13/2001");
	var d4 = new Date("May 15, 2010");
	alert("d1.toLocaleString() = " + d1.toLocaleString() +
		"\nd1.toString()       = " + d1.toString() +
		"\nd2.toLocaleString() = " + d2.toLocaleString() +
		"\nd2.toString()       = " + d2.toString() +
		"\nd3.toLocaleString() = " + d3.toLocaleString() +
		"\nd3.toString()       = " + d3.toString() +
		"\nd4.toLocaleString() = " + d4.toLocaleString() +
		"\nd4.toString()       = " + d4.toString());
	

	var d5 = new Date(Date.UTC(2001,0,1,0,0));
	var d6 = new Date(Date.UTC(2001,11,31,23,59,59,59));
	var d7 = new Date(Date.UTC(2001,11,31,23,59,59,999));
	var d8 = new Date(2001,0,1,0,0);
	var d9 = new Date(2001,11,31,23,59,59,59);
	alert("d5.toLocaleString() = " + d5.toLocaleString() +
		"\nd5.toString()       = " + d5.toString() +
		"\nd6.toLocaleString() = " + d6.toLocaleString() +
		"\nd6.toString()       = " + d6.toString() +
		"\nd7.toLocaleString() = " + d7.toLocaleString() +
		"\nd7.toString()       = " + d7.toString() +
		"\nd8.toLocaleString() = " + d8.toLocaleString() +
		"\nd8.toString()       = " + d8.toString() +
		"\nd9.toLocaleString() = " + d9.toLocaleString() +
		"\nd9.toString()       = " + d9.toString());
}

function fun2(){
	var d1 = new Date(2011,6,23);
	var d2 = new Date(2011,7,23);
	alert(d1 < d2);
}

function fun3(){
	var d1 = new Date();
	alert("d1.toDateString()       = " + d1.toDateString() +
		"\nd1.toTimeString()       = " + d1.toTimeString() +
		"\nd1.toLocaleDateString() = " + d1.toLocaleDateString() +
		"\nd1.toLocaleTimeString() = " + d1.toLocaleTimeString() +
		"\nd1.toUTCString()        = " + d1.toUTCString()
		);
}

function fun4(){
	var d1 = new Date();
	
	//getXxx()
	var gt1 = d1.getTime();
	alert(" d1 = " + d1 + "d1.getTime() = " + gt1);
	var gy1 = d1.getFullYear();
	alert("d1 = " + d1 + "d1.getFullYear() = " + gy1);
	var gutcy1 = d1.getUTCFullYear();
	alert("d1 = " + d1 + "d1.getUTCFullYear() = " + gutcy1);
	var gm1 = d1.getMonth();
	alert("d1 = " + d1 + "d1.getMonth() = "+ gm1);
	var gutcm1 = d1.getUTCMonth();
	alert("d1 = " + d1 + "d1.getUTCMonth() = " + gutcm1);
	var gd1 = d1.getDate();
	alert("d1 = " + d1 + "d1.getDate() = " + gd1);
	var gutcd1 = d1.getUTCDate();
	alert("d1 = " + d1 + "d1.getUTCDate() = " + gutcd1);
	var gw1 = d1.getDay();
	alert("d1 = " + d1 + "d1.getDay() = " + gw1);
	var gutcw1 = d1.getUTCDay();
	alert("d1 = " + d1 + "d1.getUTCDay() = " + gutcw1);
	var gh1 = d1.getHours();
	alert("d1 = " + d1 + "d1.getHours() = " + gh1);
	var gutch1 = d1.getUTCHours();
	alert("d1 = " + d1 + "d1.getUTCHours() = " + gutch1);
	var gmi1 = d1.getMinutes();
	alert("d1 = " + d1 + "d1.getMinutes() = " + gmi1);
	var gutcmi1 = d1.getUTCMinutes();
	alert("d1 = " + d1 + "d1.getUTCMinutes() = " + gutcmi1);
	var gs1 = d1.getSeconds();
	alert("d1 = " + d1 + "d1.getSeconds() = " + gs1);
	var gutcs1 = d1.getUTCSeconds();
	alert("d1 = " + d1 + "d1.getUTCSeconds() = " + gutcs1);
	var gms1 = d1.getMilliseconds();
	alert("d1 = " + d1 + "d1.Milliseconds() = " + gms1);
	var gtzo = d1.getTimezoneOffset();
	alert("d1 = " + d1 + "d1.getTimezoneOffset() = " + gtzo);

}


今天这部分的内容有点少,主要的重点放在下面做的时钟上


<!--==========================================================================
#     FileName: ex7.html
#         Desc: 
#       Author: baobaoyeye
#        Email: bao.renyi@gmail.com
#     HomePage: http://karloo.com http://blog.csdn.net/baobaoyeye
#      Version: 0.0.1
#   LastChange: 2011-07-26 08:29:38
#      History:
#==========================================================================-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="ex7.js" defer="defer" type="text/javascript"></script>
<title>This is a test of Date in javascript</title>
</head>
<body>
<div>
<input type="button" value="fun1btn1" οnclick="fun1()" />
</div>
<div>
<input type="button" value="fun2btn1" οnclick="fun2()" />
</div>
<div>
<input type="button" value="fun3btn1" οnclick="fun3()" />
</div>
<div>
<input type="button" value="fun4btn1" οnclick="fun4()" />
</div>
</body>
</html>



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值