JavaScript getTime() Method

You are Here:

JavaScript getTime() Method

The getTime() method returns a number representing the milliseconds elapsed between 1 January 1970 00:00:00 UTC and the given date.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Click the button to display the number of milliseconds from 1 January 1970 00:00:00 to current date.</p> <button onclick="myFunction()">Diplay Time</button> <p id="point"></p> <script> function myFunction() { var d = new Date(); var n = d.getTime(); document.getElementById("point").innerHTML = n; } </script> </body> </html>

Syntax

Date.getTime()

Return Value

ValueExplanation
NumberReturns a number representing the milliseconds elapsed between 1 January 1970 00:00:00 UTC and the given date.

Get Time from Specific Date

In the following example, we will get the time from a specific date.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Click the button to display the number of milliseconds from 1 January 1970 00:00:00 to May 19, 1995 02:30:25.</p> <button onclick="myFunction()">Diplay Time</button> <p id="point"></p> <script> function myFunction() { var d = new Date("May 19, 1995 02:30:25"); var n = d.getTime(); document.getElementById("point").innerHTML = n; } </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author