Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date.
The difference between the Date.UTC function and the Date object constructor that accepts a date is that the Date.UTC function assumes UTC, and the Date object constructor assumes local time.
The following example illustrates the use of the Date.UTC function.
// Determine the milliseconds per day. var MinMilli = 1000 * 60; var HrMilli = MinMilli * 60; var DyMilli = HrMilli * 24; var date = new Date("June 1, 1990"); var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDay(); var newDay = new Date("January 16, 2020"); var yeartoday = newDay.getUTCFullYear(); var monthtoday = newDay.getUTCMonth(); var dayofmonthtoday = newDay.getUTCDate(); // Get the milliseconds since 1/1/1970 UTC. var t1 = Date.UTC(year, month - 1, day) var t2 = Date.UTC(yeartoday, monthtoday, dayofmonthtoday); // Determine the difference in days. var days = (t2 - t1) / DyMilli; document.write(days); // Output: 10848
Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.