
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get current date/time in seconds in JavaScript?
To convert time in seconds, firstly get the current time. Then, multiply the hours to 3600 and minutes to 60; rest you can see below −
(hours*3600) + (min*60) + sec
Example
You can try to run the following code to get the current time in seconds −
<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>
Output
Seconds: 35 Minutes: 37 Hours: 9 Total seconds: 34655
- Related Questions & Answers
- Get current date/time in seconds - JavaScript?
- How to get current date/time in milli seconds in Java?
- How to get current date and time in JavaScript?
- How to get current date and time using JavaScript?
- How to get current date and time in Python?
- How to get current time and date in C++?
- How do I get the current date and time in JavaScript?
- Java Program to Get Current Date/Time
- How to get the current date and time in Java?
- How to get (format) date and time from mill seconds in Java?
- Get current time and date on Android
- How to get current date and time from internet in android?
- How to get current date and time from internet in iOS?
- How to get the current local date and time in Kotlin?
- How to insert current date/time in MySQL?
Advertisements