Skip to content
Related Articles

Related Articles

JavaScript Date setTime() Function
  • Difficulty Level : Medium
  • Last Updated : 04 Mar, 2021

The setTime() Function is a BuiltIn Function in Javascript Which is used to get a date object by adding given milliseconds to date 01/01/1970

Syntax:

date.setTime(milliseconds)

Parameters: setTime() Function takes parameters as follows.

  • milliseconds : Number of milliseconds to add to given date

Return Value: The setTime() Function returns milliseconds that you passed in parameter.

Example 1: Adding 30000 milliseconds to 01/01/1970



Javascript




<!DOCTYPE html>
<html lang="en">
<body>
    <script>
        // Initialization
        let date = new Date();
  
        // Execution
        let output = date.setTime(30000);
  
        // Display Output
        console.log(`setTime() Output:`, output, date);
    </script>
</body>
</html>

Output:

Example 2: Adding 2000 milliseconds to 01/01/1970

Javascript




<!DOCTYPE html>
<html lang="en">
<body>
    <script>
        // Initialization
        let date = new Date('6-29-2000 03:15:10:50');
  
        // Execution
        let output = date.setTime(2000);
  
        // Display Output
        console.log(`setTime() Output:`, output, date);
    </script>
</body>
</html>

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :