當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


javascript Date constructor用法及代碼示例


在JavaScript中,Date構造函數屬性返回對象的構造函數。對於JavaScript,日期構造函數屬性返回函數Date() {[本機代碼]}。

用法:

Date.constructor

範例1:本示例使用構造函數屬性,並返回日期構造函數。


<!DOCTYPE html> 
<html> 
    <head> 
        <title> 
            JavaScript | Date constructor Property 
        </title> 
    </head> 
    <body> 
        <center> 
            <div style="background-color:green;"> 
                  
                <h1>Welcome to GeeksforGeeks!.</h1> 
                  
                <p>  
                    It returns the function that  
                    created the string's prototype:
                </p> 
                  
                <h1 id="demo"></h1> 
            </div> 
        </center> 
          
        <script> 
            var dy = new Date(); 
            document.getElementById("demo").innerHTML 
                    = dy.constructor; 
        </script> 
    </body> 
</html>

輸出:

範例2:本示例使用構造函數屬性,並返回日期構造函數。

<!DOCTYPE html> 
<html> 
    <head> 
        <title> 
            JavaScript | Date constructor Property 
        </title> 
    </head> 
    <body> 
        <center> 
            <div style="background-color:white;"> 
                  
                <h1>Welcome to GeeksforGeeks!.</h1> 
                  
                <h3> 
                    It returns the function that created 
                    the string's prototype:
                </h3> 
                  
                <p id="name" style="background-color:green;"> 
                </p> 
            </div> 
        </center> 
        <script> 
            var dy = new Date(); 
            document.getElementById("name").innerHTML 
                    = dy.constructor; 
        </script> 
    </body> 
</html>

輸出:

支持的瀏覽器:下麵列出了JavaScript Date構造器屬性支持的瀏覽器:

  • 穀歌瀏覽器
  • 實習探險家
  • 火狐瀏覽器
  • Opera
  • 蘋果瀏覽器


相關用法


注:本文由純淨天空篩選整理自AdeshSingh1大神的英文原創作品 JavaScript | Date constructor Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。