Open In App

HTML | DOM ins dateTime Property

Last Updated : 15 Apr, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The DOM ins DateTime Property is used to set or return the value of the DateTime attribute of the <ins> Element. This attribute is used to specify the date and time of the inserted text. The date-time is inserted in the format YYYY-MM-DDThh:mm:ssTZD.

Syntax:

  • It is used to return the DateTime property.
    insObject.dateTime
  • It is used to set the dateTime property.
    insObject.dateTime = YYYY -MM-DDThh:mm:ssTZD
  • Property Values:

    • YYYY-MM-DDThh:mm:ssTZD YYYY-MM-DDThh:mm:ssTZD It specifies the date and time when the text was inserted or change in place of other text.

    Explanation:

    • YYYY – year (e.g. 2009)
    • MM – month (e.g. 01 for January)
    • DD – day of the month (e.g. 08)
    • T – a required separator
    • hh – hour (e.g. 22 for 10.00pm)
    • mm – minutes (e.g. 55)
    • ss – seconds (e.g. 03)
    • TZD – Time Zone Designator (Z denotes Zulu, also known as Greenwich Mean Time)

    Return value: It returns a string value which represent the date and time when the text was inserted and changed in place of other text.

    Example-1: This Example that illustrate how to return the datetime Property.




    <!DOCTYPE html>
    <html>
      
    <head>
        <title>DOM ins dataTime Property
      </title>
        <style>
            del {
                color: red;
            }
              
            ins {
                color: green;
            }
              
            h1 {
                color: green;
            }
              
            body {
                text-align: center;
            }
        </style>
    </head>
      
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>DOM ins dataTime Property</h2>
      
        <p>GeeksforGeeks is a
            <del>mathematical</del>
      
            <!-- Assigning id to 
                 'ins' tag -->
            <ins id="GFG"
                 datetime="2018-11-21T15:55:03Z"
                computer 
            </ins>scienceportal</p>
      
        <button onclick="myGeeks()">
          Submit
        </button>
        
        <p id="sudo">
            <script>
                function myGeeks() {
      
                    <!-- Return dateTime -->
                    var g = 
                        document.getElementById(
                      "GFG").dateTime;
                    document.getElementById(
                      "sudo").innerHTML = g;
                }
            </script>
    </body>
      
    </html>

    
    

    Output:
    Before Clicking On Button:

    After Clicking On Button:

    Example-2: This Example that illustrate how to set the dateTime Property.




    <html>
      
    <head>
        <title>
          DOM ins dataTime Property
      </title>
        <style>
            del {
                color: red;
            }
              
            ins {
                color: green;
            }
              
            h1 {
                color: green;
            }
              
            body {
                text-align: center;
            }
        </style>
    </head>
      
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>DOM ins dataTime Property</h2>
      
        <p>GeeksforGeeks is a
            <del>mathematical</del>
      
            <!-- Assigning id to 'ins' tag -->
            <ins id="GFG"
                 datetime="2018-11-21T15:55:03Z"
                computer 
            </ins>scienceportal</p>
      
        <button onclick="myGeeks()">
          Submit
      </button>
        <p id="sudo">
            <script>
                function myGeeks() {
      
                    <!-- Return dateTime -->
                    var g = 
                        document.getElementById(
                      "GFG").dateTime = "2015-10-19T22:45:07Z";
                    document.getElementById("sudo").innerHTML = 
                  "The value of the dateTime attribute was hanged to "
                    + g;
                }
            </script>
    </body>
      
    </html>

    
    

    Output:
    Before Clicking On Button:

    After Clicking On Button:

    Supported Browsers: The browser supported by DOM ins datetime Property are listed below:

    • Google Chrome
    • Internet Explorer
    • Firefox
    • Opera
    • Safari


    Like Article
    Suggest improvement
    Previous
    Next
    Share your thoughts in the comments

Similar Reads