Date 对象用于处理日期与实际。
创建 Date 对象:
var now = new Date().
| 方法 | 描述 | 
|---|---|
| getDate() | 从 Date 对象返回一个月中的某一天 (1 ~ 31)。 | 
| getDay() | 从 Date 对象返回一周中的某一天 (0 ~ 6)。 | 
| getFullYear() | 从 Date 对象以四位数字返回年份。 | 
| getHours() | 返回 Date 对象的小时 (0 ~ 23)。 | 
| getMilliseconds() | 返回 Date 对象的毫秒(0 ~ 999)。 | 
| getMinutes() | 返回 Date 对象的分钟 (0 ~ 59)。 | 
| getMonth() | 从 Date 对象返回月份 (0 ~ 11)。 | 
| getSeconds() | 返回 Date 对象的秒数 (0 ~ 59)。 | 
| setDate() | 设置 Date 对象中月的某一天 (1 ~ 31)。 | 
| setFullYear() | 设置 Date 对象中的年份(四位数字)。 | 
| setHours() | 设置 Date 对象中的小时 (0 ~ 23)。 | 
| setMilliseconds() | 设置 Date 对象中的毫秒 (0 ~ 999)。 | 
| setMinutes() | 设置 Date 对象中的分钟 (0 ~ 59)。 | 
| setMonth() | 设置 Date 对象中月份 (0 ~ 11)。 | 
| setSeconds() | 设置 Date 对象中的秒钟 (0 ~ 59)。 | 
| setTime() | setTime() 方法以毫秒设置 Date 对象。 | 
<script type="text/javascript"> var span = document.getElementById("spandate"); var now = new Date(); var year = now.getFullYear();//年 var month = now.getMonth() + 1;//月 (注意:月份+1) var date = now.getDate();//日 if (month < 10) { month = "0" + month; } if (date < 10) { date = "0" + date; } span.innerText = year + "-" + month + "-" + date; </script>
原文:http://www.cnblogs.com/Tanghongchang/p/7345327.html