javascript當(dāng)中Date對象用法
Date對象
馬克- to-win:馬克 java社區(qū):防盜版實名手機(jī)尾號: 73203。
例 2.1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<Script>
/*馬克-to-win:Global有個Date()這個方法。*/
/*When the Global object is created, it always has at least the following properties:
Object object Function object Array object String object
Boolean object Number object Date object Math object
Value properties
*/
var today = new Date();
var month = today.getMonth()+1;
var date = today.getDate();
var day = today.getDay();
document.write("今天是");
document.write(month+"月");
document.write(date+"日");
document.write("星期"+day);//注意:是阿拉伯?dāng)?shù)字并非中文;請試改為中文習(xí)慣
var s="調(diào)試站位";
</Script>
</head>
<body>
</body>
</html>
輸出結(jié)果:
今天是10月16日星期1
例 2.2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</head>
<SCRIPT LANGUAGE="JavaScript">
<!-- 馬克-to-win
var d = new Date(); // 創(chuàng)建 Date 對象
d.setMonth(7-1); // 設(shè)置月份
d.setDate(8); // 設(shè)置日期
d.setHours(1);
d.setMinutes(3);
d.setSeconds(5);
document.write(d);
document.write(d.toLocaleString());
//-->
</SCRIPT>
</head>
<body>
</body>
</html>
輸出結(jié)果:
Sat Jul 08 2017 01:03:05 GMT+08002017/7/8 上午1:03:05