Greenwich Mean Time to Zulu Time Calculator. Greenwich Mean Time (GMT) Zulu Time. Greenwich Mean Time Offset: UTC +0. NOTE: I will always use UTC when sending over the wire. Client-side JS can easily get to/from local UTC. See: new Date.toJSON. The following JS will handle parsing a UTC/GMT date in ISO8601 format to a local datetime.
I need to force any time related operations to GMT/UTC. For an offset of zero hours-minutes-seconds, use the constant ZoneOffset.UTC. To capture the current moment in UTC, use an Instant. This class represent a moment in UTC, always in UTC by definition. Instant instant = Instant.now; // Capture current moment in UTC.
The Date.UTC()
method accepts parameters similar to the Date
constructor, but treats them as UTC. It returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.
Syntax
year
- A full year.
month
Optional- An integer between
0
(January) and11
(December) representing the month. Since ECMAScript 2017 it defaults to0
if omitted. (Up until ECMAScript 2016,month
was a required parameter. As of ES2017, it no longer is.) day
Optional- An integer between
1
and31
representing the day of the month. If omitted, defaults to1
. hour
Optional- An integer between
0
and23
representing the hours. If omitted, defaults to0
. minute
Optional- An integer between
0
and59
representing the minutes. If omitted, defaults to0
. second
Optional- An integer between
0
and59
representing the seconds. If omitted, defaults to0
. millisecond
Optional- An integer between
0
and999
representing the milliseconds. If omitted, defaults to0
.
Return value
A number representing the number of milliseconds for the given date since January 1, 1970, 00:00:00, UTC.
Description
UTC()
takes comma-delimited date and time parameters and returns the number of milliseconds between January 1, 1970, 00:00:00, universal time and the specified date and time.
Years between 0
and 99
are converted to a year in the 20th century (1900 + year)
. For example, 95
is converted to the year 1995
.
The UTC()
method differs from the Date
constructor in two ways:
Date.UTC()
uses universal time instead of the local time.Date.UTC()
returns a time value as a number instead of creating aDate
object.
If a parameter is outside of the expected range, the UTC()
method updates the other parameters to accommodate the value. For example, if 15
is used for month
, the year will be incremented by 1 (year + 1)
and 3
will be used for the month.
UTC()
is a static method of Date
, so it's called as Date.UTC()
rather than as a method of a Date
instance.
Examples
Using Date.UTC()
Gmt To Utc 1
The following statement creates a Date
object with the arguments treated as UTC instead of local:
Specifications
Greenwich Mean Time to Zulu Time Calculator. Greenwich Mean Time (GMT) Zulu Time. Greenwich Mean Time Offset: UTC +0. NOTE: I will always use UTC when sending over the wire. Client-side JS can easily get to/from local UTC. See: new Date.toJSON. The following JS will handle parsing a UTC/GMT date in ISO8601 format to a local datetime.
I need to force any time related operations to GMT/UTC. For an offset of zero hours-minutes-seconds, use the constant ZoneOffset.UTC. To capture the current moment in UTC, use an Instant. This class represent a moment in UTC, always in UTC by definition. Instant instant = Instant.now; // Capture current moment in UTC.
The Date.UTC()
method accepts parameters similar to the Date
constructor, but treats them as UTC. It returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.
Syntax
year
- A full year.
month
Optional- An integer between
0
(January) and11
(December) representing the month. Since ECMAScript 2017 it defaults to0
if omitted. (Up until ECMAScript 2016,month
was a required parameter. As of ES2017, it no longer is.) day
Optional- An integer between
1
and31
representing the day of the month. If omitted, defaults to1
. hour
Optional- An integer between
0
and23
representing the hours. If omitted, defaults to0
. minute
Optional- An integer between
0
and59
representing the minutes. If omitted, defaults to0
. second
Optional- An integer between
0
and59
representing the seconds. If omitted, defaults to0
. millisecond
Optional- An integer between
0
and999
representing the milliseconds. If omitted, defaults to0
.
Return value
A number representing the number of milliseconds for the given date since January 1, 1970, 00:00:00, UTC.
Description
UTC()
takes comma-delimited date and time parameters and returns the number of milliseconds between January 1, 1970, 00:00:00, universal time and the specified date and time.
Years between 0
and 99
are converted to a year in the 20th century (1900 + year)
. For example, 95
is converted to the year 1995
.
The UTC()
method differs from the Date
constructor in two ways:
Date.UTC()
uses universal time instead of the local time.Date.UTC()
returns a time value as a number instead of creating aDate
object.
If a parameter is outside of the expected range, the UTC()
method updates the other parameters to accommodate the value. For example, if 15
is used for month
, the year will be incremented by 1 (year + 1)
and 3
will be used for the month.
UTC()
is a static method of Date
, so it's called as Date.UTC()
rather than as a method of a Date
instance.
Examples
Using Date.UTC()
Gmt To Utc 1
The following statement creates a Date
object with the arguments treated as UTC instead of local:
Specifications
Specification |
---|
ECMAScript Language Specification (ECMAScript) #sec-date.utc |
Browser compatibility
BCD tables only load in the browser
Compatibility notes
Gmt To Utc Python
Date.UTC() with fewer than two arguments
When providing less than two arguments to Date.UTC()
, ECMAScript 2017 requires that NaN
is returned. Engines that weren't supporting this behavior have been updated (see bug 1050755, ecma-262 #642).