How to convert epoch Date to meaningful JavaScript date?

JavascriptWeb DevelopmentFront End Technology

Dates in JavaScript take milliseconds since epoch. If the epoch in milliseconds is 1514789449605, then let us convert it into a meaningful JavaScript date.

Example

Live Demo

<html>
   <head>
      <title>JavaScript Dates</title>
   </head>
   <body>
      <script>
         var val ="/Date(1514789449605)/";
         var myDate = new Date( parseFloat( val.substr(6 )));
         document.write("Converted Date:"+ (myDate.getMonth() + 1) + "/" +
                      myDate.getDate() + "/" + myDate.getFullYear() + " " +
                      myDate.getHours() + ":" + myDate.getMinutes() + ":" +
                      myDate.getSeconds()
         );
      </script>
   </body>
</html>

Output

Converted Date:1/1/2018 12:20:49
raja
Published on 14-Feb-2018 07:11:50
Advertisements