
[JavaScript-Date物件]Date物件,取得日期的年getFullYear、月getMonth、日getDate
用途: 取得日期的年取得日期的月取得日期的日 說明:
PG Levin Li 發表在 痞客邦 留言(0) 人氣(443)

用途:
本地格式顯示日期時間
說明:
var d = new Date();
d.toLocaleString();
程式範例:
<script type ="text/javascript">
//宣告一個日期的變數,並取得現在日期。
var d = new Date();
//將現在日期顯示在頁面上
document.write("依本地格式顯示日期/時間:"+d.toLocaleString());
</script>
測試結果:
PG Levin Li 發表在 痞客邦 留言(0) 人氣(190)

用途:
取得毫秒數
說明:
var d = new Date();
d.getTime()
程式範例:
<script type ="text/javascript">
//宣告一個日期的變數,並取得現在日期。
var d = new Date();
//將現在日期顯示在頁面上
document.write("毫秒數:"+d.getTime());
</script>
測試結果:
PG Levin Li 發表在 痞客邦 留言(0) 人氣(2,285)

用途:
指定時間
說明:
new Date(毫秒);
new Date(年,月,日);
new Date(年,月,日,時,分,秒);
期中的月份0~11
0為1月以此類推。
程式範例:
<script type ="text/javascript">
//宣告一個日期的變數,並取得現在日期。
//取得基準時間50000毫秒的時間
//基準時間為1970年1月1日0時0秒
var d = new Date(1000);
//將現在日期顯示在頁面上
document.write("時間為:"+d);
document.write("<br>");
d = new Date(2014,1,10);
//將現在日期顯示在頁面上
document.write("指定時間為:"+d);
document.write("<br>");
d = new Date(2014,1,10,8,30,30);
//將現在日期顯示在頁面上
document.write("指定時間為:"+d);
</script>
測試結果:
PG Levin Li 發表在 痞客邦 留言(0) 人氣(338)

用途:
取得目前的日期時間
說明:
取得日期
new Date();
程式範例:
<script type ="text/javascript">
//宣告一個日期的變數,並取得現在日期。
var d = new Date();
//將現在日期顯示在頁面上
document.write("目前時間為:"+d);
</script>
測試結果:
PG Levin Li 發表在 痞客邦 留言(0) 人氣(1,532)