JavaScript getTime Function

JavaScript getTime function is one a Date Function, which returns the Time from a given date. This getTime function returns the total number of Milliseconds from January 1, 1970 to a given date. We are using JavaScript getTime to return the number of Milliseconds from the default date to the current date and time.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Get Time Function </title>
</head>
<body>
    <h1> JavaScript getiTime Function Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt);
  document.write("Time using getTime(): " + dt.getTime());
</script>
</body>
</html>
JavaScript getTime Function Example

Date and Time: Sun Nov 04 2018 15:48:43 GMT+0530 (Indian Standard Time)
Time from getTime(): 1541326723757

JavaScript getTime Function Example

In this example, we are using JavaScrip get Time function on the custom date

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Get Time Function </title>
</head>
<body>
    <h1> JavaScript getTime Function Example </h1>
<script>
  var dt = Date("December 22, 2002 10:11:43");
  document.write("Date and Time : " + dt);
  document.write("Time using getTime(): " + dt.getTime());
</script>
</body>
</html>
JavaScript getTime Function 2

JavaScript get Time Function Example

In this example, we are using JavaScript get Time on the custom date without the time. This function considers the time as 00:00:00 and returns the milliseconds from default time (1 January 1970) to the specified date.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Get Time Function </title>
</head>
<body>
    <h1> JavaScript getTime Function Example </h1>
<script>
  var dt = Date("December 22, 1972");
  document.write("Date and Time : " + dt);
  document.write("Time using getTime(): " + dt.getTime());
</script>
</body>
</html>
JavaScript getTime Function Example

Date and Time: Fri Dec 22 1972 00:00:00 GMT+0530 (Indian Standard Time)
Time from getTime(): 93810600000