
- 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
Get current date/time in seconds - JavaScript?
At first, get the current date −
var currentDateTime = new Date();
To get the current date/time in seconds, use getTime()/1000.
Example
Following is the code −
var currentDateTime = new Date(); console.log("The current date time is as follows:"); console.log(currentDateTime); var resultInSeconds=currentDateTime.getTime() / 1000; console.log("The current date time in seconds is as follows:") console.log(resultInSeconds);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo285.js.
Output
This will produce the following output on console −
The current date time is as follows: 2020-08-28T16:13:35.987Z The current date time in seconds is as follows: 1598631215.987
- Related Articles
- How to get current date/time in seconds in 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?
- Java Program to Get Current Date/Time
- Get current time and date on Android
- How to get current time and date in C++?
- How to get current date and time in Python?
- How to get the current date and time in Java?
- How to get (format) date and time from mill seconds in Java?
- How can I get the current time and date in Kotlin?
- How to get current date and time from internet in iOS?
- How to get current date and time from internet in android?
- How to get the current local date and time in Kotlin?

Advertisements