Date.UTC()

Date.UTC() returns the millisecond of a date in UTC.

The arguments for Date.UTC()

  • the year,
  • the zero-based month (January is 0, February is 1, and so on)
  • the day of the month (1 through 31),
  • the hours (0 through 23),
  • minutes,
  • seconds,
  • milliseconds

The year and month are required.

If the day of the month isn't supplied, it's assumed to be 1. all other omitted arguments are assumed to be 0.

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
    
        var aDate = new Date(Date.UTC(2000, 0)); 
        document.writeln(aDate);//Fri Dec 31 1999 16:00:00 GMT-0800 (Pacific Standard Time)


    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo

months are zero-based hours are represented as 0 through 23.

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var aDate = new Date(Date.UTC(2021, 5, 4, 12, 21, 55)); 
        document.writeln(aDate);//Fri Jun 04 2021 05:21:55 GMT-0700 (Pacific Daylight Time)
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Essential Types  

Date:
  1. Date Type
  2. Date getter
  3. Date Setter
  4. Date.parse()
  5. Date.UTC()
  6. Date.now()
  7. Date toLocaleString()
  8. Date toString()
  9. Date valueOf()
  10. Date toDateString()
  11. Date toTimeString()
  12. Date toLocaleDateString()
  13. Date toLocaleTimeString()
  14. Date toUTCString()