JavaScript日期构造函数属性

2021年3月23日14:58:41 发表评论 655 次浏览

在JavaScript中, 日期构造器属性返回对象的构造函数。对于JavaScript Date构造函数属性返回函数Date(){[本地代码]}.

语法如下:

Date.constructor

返回值:它返回函数Date(){[本地代码]}。

上述属性的更多示例代码如下:

范例1:

本示例使用构造函数属性, 并返回日期构造函数。

<!DOCTYPE html> 
< html > 
  
< head > 
     < title > 
         JavaScript Date constructor Property 
     </ title > 
</ head > 
  
< body style = "text-align:center;" > 
  
     < div > 
              
         < h1 style = "color: green;" >lsbin</ h1 > 
                  
         < p > 
             JavaScript Date constructor Property 
             returns the function that created the 
             Date's prototype: 
         </ p > 
                  
         < b id = "GFG" ></ b > 
          
     </ div > 
      
     <!-- Script to use date constructor -->
     < script > 
         var dy = new Date();
         document.getElementById("GFG").innerHTML 
                 = dy.constructor; 
     </ script > 
</ body > 
  
</ html >

输出如下:

JavaScript日期构造函数属性1

范例2:本示例使用构造函数属性, 并返回日期构造函数。

<!DOCTYPE html> 
< html > 
  
< head > 
     < title > 
         JavaScript Date constructor Property 
     </ title > 
</ head > 
  
< body style = "text-align:center;" > 
  
     < div > 
              
         < h1 style = "color: green;" >lsbin</ h1 > 
                  
         < p > 
             JavaScript Date constructor Property 
             returns the function that created 
             the Date's prototype: 
         </ p > 
         < button onclick = "gfg()" >Click me</ button > 
         < p id = "GFG" ></ p > 
     </ div > 
      
     <!-- Script to use Date constructor Property -->
     < script > 
     function gfg(){ 
         var dy = new Date();
         document.getElementById("GFG").innerHTML 
                 = dy.constructor; 
     } 
     </ script > 
</ body > 
  
</ html >

输出如下:

JavaScript日期构造函数属性2

支持的浏览器:支持的浏览器JavaScript日期构造函数属性下面列出:

  • 谷歌浏览器
  • 实习探险家
  • 火狐浏览器
  • 歌剧
  • 苹果浏览器

木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: