当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。