要以秒为单位转换时间,首先要获取当前时间。然后,将小时数乘以3600,将分钟数乘以60;其余你可以在下面看到-
(hours*3600) + (min*60) + sec
您可以尝试运行以下代码以秒为单位获取当前时间-
<html>
   <head>
      <title>JavaScript Get Seconds</title>
   </head>
   <body>
      <script>
         var dt = new Date();
         var sec = dt.getSeconds();
         document.write("Seconds: " + sec);
         var min = dt.getMinutes();
         document.write("<br>Minutes: " + min);
         var hrs = dt.getHours();
         document.write("<br>Hours: " + hrs);
         var total_seconds = (hrs*3600) + (min*60) + sec;
         document.write("<br>Total seconds: " + total_seconds) ;
      </script>
   </body>
</html>输出结果
Seconds: 35 Minutes: 37 Hours: 9 Total seconds: 34655