物件 Date 的一系列 get 方法。
方法 getDate() 會傳回物件實體的月之日。
- 程式用法:
<script type='text/javascript'>
var today=new Date();
document.write( today.getDate() );
</script> - 執行結果:
1
方法 getDay() 會傳回物件實體的週之日。0 是週日, 1 是週一,餘類推。
- 程式用法:
<script type='text/javascript'>
document.write( today.getDay() );
</script> - 執行結果:
2
方法 getFullYear() 會傳回物件實體的四位數西元年。
- 程式用法:
<script type='text/javascript'>
document.write( today.getFullYear() );
</script> - 執行結果:
2025
方法 getHours() 會傳回物件實體的本地日之時。
- 程式用法:
<script type='text/javascript'>
document.write( today.getHours() );
</script> - 執行結果:
19
方法 getMilliseconds() 會傳回物件實體的時間之微秒。
- 程式用法:
<script type='text/javascript'>
document.write( today.getMilliseconds() );
</script> - 執行結果:
115
方法 getMinutes() 會傳回物件實體的時間之分鐘。
- 程式用法:
<script type='text/javascript'>
document.write( today.getMinutes() );
</script> - 執行結果:
41
方法 getMonth() 會傳回物件實體的月份。數值由 0 至 11,0 為一月,餘類推。
- 程式用法:
<script type='text/javascript'>
document.write( today.getMonth() );
</script> - 執行結果:
3
方法 getSeconds() 會傳回物件實體的時間之秒。
- 程式用法:
<script type='text/javascript'>
document.write( today.getSeconds() );
</script> - 執行結果:
1
方法 getTime() 會傳回物件實體的時間之總微秒數(自 1970/1/1 0:0:0 起算)。
- 程式用法:
<script type='text/javascript'>
document.write( today.getTime() );
</script> - 執行結果:
1743536461115
方法 getTimezoneOffset() 會傳回物件實體的本地時區相對於 GMT 的差值。
- 程式用法:
<script type='text/javascript'>
document.write( today.getTimezoneOffset() );
</script> - 執行結果:
0
方法 getUTCDate() 會傳回物件實體的日期換成 UTC 的月之日。
- 程式用法:
<script type='text/javascript'>
document.write( today.getUTCDate() );
</script> - 執行結果:
1
方法 getUTCDay() 會傳回物件實體的日期換成 UTC 的週之日。
- 程式用法:
<script type='text/javascript'>
document.write( today.getUTCDay() );
</script> - 執行結果:
2
方法 getUTCFullYear() 會傳回物件實體的日期換成 UTC 的四位數西元年。
- 程式用法:
<script type='text/javascript'>
document.write( today.getUTCFullYear() );
</script> - 執行結果:
2025
方法 getUTCHours() 會傳回物件實體的日期換成 UTC 的日之時。
- 程式用法:
<script type='text/javascript'>
document.write( today.getUTCHours() );
</script> - 執行結果:
19
方法 getUTCMilliseconds() 會傳回物件實體的日期換成 UTC 的時間之微秒。
- 程式用法:
<script type='text/javascript'>
document.write( today.getUTCMilliseconds() );
</script> - 執行結果:
115
方法 getUTCMinutes() 會傳回物件實體的日期換成 UTC 的時間之分鐘。
- 程式用法:
<script type='text/javascript'>
document.write( today.getUTCMinutes() );
</script> - 執行結果:
41
方法 getUTCMonth() 會傳回物件實體的日期換成 UTC 的年之月。數值由 0 至 11,0 為一月,餘類推。
- 程式用法:
<script type='text/javascript'>
document.write( today.getUTCMonth() );
</script> - 執行結果:
3
方法 getUTCSeconds() 會傳回物件實體的日期換成 UTC 的時間之秒。
- 程式用法:
<script type='text/javascript'>
document.write( today.getUTCSeconds() );
</script> - 執行結果:
1
方法 getYear() 會傳回物件實體的年數。已廢止,不同瀏覽器,回傳值不同。建議勿用,改用 getFullYear()。
- 程式用法:
<script type='text/javascript'>
document.write( today.getYear() );
</script> - 執行結果:
125