Ex No: 4 DISPLAY DATE AND TIME
Aim: To write a JavaScript code to display date and time using Date() object.
Algorithm
Step1: Create a folder “Ex4” to place the HTML files.
Step2: Create HTML file “index.html”.
Step3: Use JavaScript Date() object to get todays Date and Time.
Step4: Use Date() objects get Methods display date and time.
Step5: Using JavaScript display the result in a label.
Source Code

index.html


<!DOCTYPE html>
<html>
    <head>
        <title>Date and Time</title>    
    <style>
      header {
        text-align:center;
        height: 100px;
        background-color: lime;
        padding: 10px;
        border-radius: 10px 10px 0px 0px;
      }
      footer {
        text-align:center;
        font-size: 12px;
        height: 50px;
        line-height: 50px;
        background-color: lime;
        padding: 10px;
        border-radius: 10px;
      }
      article{
        width: auto;
        padding: 10px;
        margin:5px;
        overflow-x: auto;
      }
    </style>
    <script type="text/javascript">
    function time()
    {
      let fdate, dt, time;
      fdate = new Date();
      document.getElementById('fdate').innerHTML = fdate;  
      dt = fdate.getDate()+"/"+fdate.getMonth()+"/"+fdate.getFullYear();
      document.getElementById('date').innerHTML = dt;   
      time = fdate.getHours()+":"+fdate.getMinutes()+":"+fdate.getSeconds();
      document.getElementById('time').innerHTML = time;  
    }
    </script>
    </head>
    <body>        
        <header>
            <h1>Date and Time</h1>
        </header>    
        <hr>
        <table>
          <tr>
            <td>Full Date:</td>
            <td><label id="fdate"> </label></td>
           </tr>
          <tr>
            <td>Todays Date:</td>
            <td><label id="date"> </label></td>
           </tr>
          <tr>
            <td>Time:</td>
            <td><label id="time"> </label></td>
           </tr>
          <tr>
            <td colspan="2"><input type="button" value="Get Date & Time" onclick="time()"></td>
           </tr>
        </table>
        <footer>
            Developed by K Anbarasan
        </footer>
    </body>
</html>
Result: Thus JavaScript code is written to display Data and Time.