Set the Date Format using JavaScript

  1. <html  
  2.     xmlns="http://www.w3.org/1999/xhtml">  
  3.     <head>  
  4.         <script src="Scripts/jquery-2.1.4.min.js"></script>  
  5.         <link href="Content/bootstrap.min.css" rel="stylesheet" />  
  6.         <title>Javascript set date format </title>  
  7.     </head>  
  8.     <body >  
  9.         <h3>Date Format</h3>  
  10.         <br />  
  11.         <form id="form1" class="form">  
  12.             <div class="form-group">  
  13.                 <b>Current Date:</b>  
  14.                 <label id="Lbl_Curr_Date" style="color:blue" />  
  15.             </div>  
  16.             <div class="form-group">  
  17.                 <b>dd mm yyyy format:</b>  
  18.                 <label id="Lbl_format_1" style="color:blue" />  
  19.             </div>  
  20.             <div class="form-group">  
  21.                 <b>mm dd yyyy format </b>  
  22.                 <label id="lbl_format_2" style="color:blue"></label>  
  23.             </div>  
  24.             <div class="form-group">  
  25.                 <b>dd mm yyyy hh:mm:ss Format:</b>  
  26.                 <label id="lbl_format_3" style="color:blue" />  
  27.             </div>  
  28.         </form>  
  29.     </body>  
  30. </html>  
  31. <script type="text/javascript">  
  32.   
  33.     $(document).ready(function()  
  34.     {  
  35.         var today = new Date()  
  36.         document.getElementById('Lbl_Curr_Date').innerHTML = today;  
  37.         document.getElementById('Lbl_format_1').innerHTML = [today.getDate(), today.getMonth() + 1, today.getFullYear()].join('/');  
  38.         document.getElementById('lbl_format_2').innerHTML = [today.getMonth() + 1, today.getDate(), today.getFullYear()].join('/');  
  39.         document.getElementById('lbl_format_3').innerHTML = [today.getDate(), today.getMonth() + 1, today.getFullYear()].join('/') + ' ' + [today.getHours(), today.getMinutes(), today.getSeconds()].join(':');  
  40.     })  
  41.   
  42. </script>