- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert HH:MM:SS to seconds with JavaScript?
To convert the HH:MM:SS to seconds, you need to multiply the HOUR with 60X60 and Minute with 60:
Example
var time = '10:8:20'; var actualTime = time.split(':'); console.log("The time="+time); var totalSeconds = (+actualTime[0]) * 60 * 60 + (+actualTime[1]) * 60 + (+actualTime[2]); console.log("Total Seconds="+totalSeconds);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo61.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo61.js The time=10:8:20 Total Seconds=36500
Advertisements