
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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 Articles
- 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 do I get the current date and time in JavaScript?
- How to get current date and time in Python?
- How to get current time and date in C++?
- How to get the current date and time in Java?
- How to get (format) date and time from mill seconds in Java?
- 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?
- Java Program to Get Current Date/Time
- How do I get the current date in JavaScript?
- How to get the current time in millisecond using JavaScript?

Advertisements