JavaScript Date.UTC() Method

You are Here:

JavaScript Date.UTC() Method

The Date.UTC method returns a number representing the number of milliseconds for the given date since January 1, 1970, 00:00:00, UTC.

It takes comma-delimited date and time parameters.

Note: If a parameter is outside of the expected range, the UTC() method updates the other parameters to accommodate the value. For example, if 13 is used for month, the year will be incremented by 1 (year + 1) and 1 will be used for the month.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Display Milliseconds</button> <p id="point"></p> <script> function myFunction(){ var d = Date.UTC(1995, 04, 19); document.getElementById("point").innerHTML = d; } </script> </body> </html>

Syntax

Date.UTC(year, month, day, hour, minute, second, millisecond)

Parameter Values

ValueTypeExplanation
yearRequiredA full year.
monthOptionalAn integer between 0 (January) and 11 (December) representing the month.
dayOptionalAn integer between 1 and 31 representing the day of the month.
If omitted, defaults to 1.
hourOptional An integer between 0 and 23 representing the hours.
If omitted, defaults to 0.
minuteOptionalAn integer between 0 and 59 representing the minutes.
If omitted, defaults to 0.
secondOptionalAn integer between 0 and 59 representing the seconds.
If omitted, defaults to 0.
millisecondOptionalAn integer between 0 and 999 representing the milliseconds.
If omitted, defaults to 0.

Return Value

ValueExplanation
NumberReturns a number representing the number of milliseconds for the given date since January 1, 1970, 00:00:00, UTC.

Date.UTC() as Argument

In the following example, a Date object with the arguments treated as UTC instead of local.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Display Local Date and Time</button> <p id="point"></p> <script> function myFunction() { var d = new Date(Date.UTC(2020, 02, 25)); document.getElementById("point").innerHTML = d; } </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