Javascript Date Now Function

JavaScript Date Now function is one of the Date Function used to return the Current Date and Time in Milliseconds. This article shows you how to use Date.Now with an example.

JavaScript Date Now Example

The following example helps you understand the JavaScript now Function.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Now Function </title>
</head>
<body>
    <h1> JavaScript Date.Now() Function Example </h1>
<script>
  var dt = Date.now();
    
  document.write("Date and Time in Milliseconds : " + dt);
</script>
</body>
</html>
JavaScript Date Now Function Example

Date and Time in Milliseconds: 1541383869864

As you can see, it is returning the current date and time in milliseconds.

In this example, we are converting the Milliseconds returned by the Date.now to normal date and time. For this JavaScript example, you have to use the Js Date Function.

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

Date and Time : Mon Nov 05 2018 07:39:09 GMT+0530 (Indian Standard Time)

Date Now Function Example 2

The following example helps you understand both the Date(date.now()), and Date() function. As we said earlier, both these function returns the same result.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Now Function </title>
</head>
<body>
    <h1> JavaScript Date Now Function Example </h1>
<script>
  var dt1 = Date(Date.now());    
  document.write("Date and Time :  " + dt1 + "<br/>");
  document.write("Date and Time Example 2   <br/>");
  var dt2 = Date();   
  document.write("Date and Time :  " + dt2);
</script>
</body>
</html>
JavaScript Date Now Function 3