2008年12月11日

Date:get 方法

Date | 特徵與靜態方法 | get 方法 | set 方法 | to 方法

物件 Date 的一系列 get 方法。

getDate getDay getFullYear getHours
getMilliseconds getMinutes getMonth getSeconds
getTime getTimezoneOffset getUTCDate getUTCDay
getUTCFullYear getUTCHours getUTCMilliseconds getUTCMinutes
getUTCMonth getUTCSeconds getYear
getDate()

方法 getDate() 會傳回物件實體的月之日。

  • 程式用法:

    <script type='text/javascript'>
    var today=new Date();
    document.write( today.getDate() );
    </script>

  • 執行結果:

    1

getDay()

方法 getDay() 會傳回物件實體的週之日。0 是週日, 1 是週一,餘類推。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getDay() );
    </script>

  • 執行結果:

    2

getFullYear()

方法 getFullYear() 會傳回物件實體的四位數西元年。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getFullYear() );
    </script>

  • 執行結果:

    2025

getHours()

方法 getHours() 會傳回物件實體的本地日之時。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getHours() );
    </script>

  • 執行結果:

    19

getMilliseconds()

方法 getMilliseconds() 會傳回物件實體的時間之微秒。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getMilliseconds() );
    </script>

  • 執行結果:

    115

getMinutes()

方法 getMinutes() 會傳回物件實體的時間之分鐘。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getMinutes() );
    </script>

  • 執行結果:

    41

getMonth()

方法 getMonth() 會傳回物件實體的月份。數值由 0 至 11,0 為一月,餘類推。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getMonth() );
    </script>

  • 執行結果:

    3

getSeconds()

方法 getSeconds() 會傳回物件實體的時間之秒。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getSeconds() );
    </script>

  • 執行結果:

    1

getTime()

方法 getTime() 會傳回物件實體的時間之總微秒數(自 1970/1/1 0:0:0 起算)。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getTime() );
    </script>

  • 執行結果:

    1743536461115

getTimezoneOffset()

方法 getTimezoneOffset() 會傳回物件實體的本地時區相對於 GMT 的差值。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getTimezoneOffset() );
    </script>

  • 執行結果:

    0

getUTCDate()

方法 getUTCDate() 會傳回物件實體的日期換成 UTC 的月之日。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getUTCDate() );
    </script>

  • 執行結果:

    1

getUTCDay()

方法 getUTCDay() 會傳回物件實體的日期換成 UTC 的週之日。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getUTCDay() );
    </script>

  • 執行結果:

    2

getUTCFullYear()

方法 getUTCFullYear() 會傳回物件實體的日期換成 UTC 的四位數西元年。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getUTCFullYear() );
    </script>

  • 執行結果:

    2025

getUTCHours()

方法 getUTCHours() 會傳回物件實體的日期換成 UTC 的日之時。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getUTCHours() );
    </script>

  • 執行結果:

    19

getUTCMilliseconds()

方法 getUTCMilliseconds() 會傳回物件實體的日期換成 UTC 的時間之微秒。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getUTCMilliseconds() );
    </script>

  • 執行結果:

    115

getUTCMinutes()

方法 getUTCMinutes() 會傳回物件實體的日期換成 UTC 的時間之分鐘。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getUTCMinutes() );
    </script>

  • 執行結果:

    41

getUTCMonth()

方法 getUTCMonth() 會傳回物件實體的日期換成 UTC 的年之月。數值由 0 至 11,0 為一月,餘類推。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getUTCMonth() );
    </script>

  • 執行結果:

    3

getUTCSeconds()

方法 getUTCSeconds() 會傳回物件實體的日期換成 UTC 的時間之秒。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getUTCSeconds() );
    </script>

  • 執行結果:

    1

getYear()

方法 getYear() 會傳回物件實體的年數。已廢止,不同瀏覽器,回傳值不同。建議勿用,改用 getFullYear()。

  • 程式用法:

    <script type='text/javascript'>
    document.write( today.getYear() );
    </script>

  • 執行結果:

    125


©2008-2009 by ant2legs, All Rights Reserved. ant2legs 擁有其製作的文章,圖片與程式的著作權,所有權利保留。