समय को सेकंड में बदलने के लिए, पहले वर्तमान समय प्राप्त करें। फिर घंटे को 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