How can I get time and date since epoch in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To get time and date since epoch in JavaScript, you can try to run the following code −

Example

Live Demo

<html>
   <head>
      <title>JavaScript Clone Date</title>
   </head>
   <body>
      <script>
         var current_date, epocDate;
         current_date = new Date();
         document.write("Current Date: "+current_date);
         var epocDate = new Date(new Date().getTime() / 1000);
         document.write("<br>Since epoch: "+epocDate);
      </script>
   </body>
</html>

Output

Current Date: Mon May 28 2018 09:23:11 GMT+0530 (India Standard Time)
Since epoch: Sun Jan 18 1970 21:47:59 GMT+0530 (India Standard Time)
raja
Published on 14-Feb-2018 06:55:32
Advertisements