What do getUTC * methods do on a date object?

What does this mean when you receive or create a UTC date in JavaScript?

+6
javascript date utc
source share
3 answers

A date is a specific point in time. This point in time will be named differently in different places. When I write this, it is 00:27 on Tuesday in Germany, 23:27 on Monday in the UK and 18:27 on Monday in New York.

To take an example method: getDay returns the day of the week in the local time zone. Right now, for a user in Germany, he will return 2. For a user in the UK or USA, he will return 1. After an hour, he will return 2 for a user in the UK (because then it will be 00: 27 on Tuesday).

The methods..UTC .. refer to the representation of time in UTC (also known as GMT). In winter, this is the same time zone as in the UK; in summer, it lags behind time in the UK.

It is summer when I write this. getUTCDay will return 1 (Monday), getUTCHours will return 22, getUTCMinutes will return 27. So it is 22:27 on Monday in the UTC time zone. While plain get ... functions return different values ​​depending on where the user is located, getUTC .. functions return the same values ​​regardless of where the user is.

+12
source share

getUTC is designed to convert time into coordinated universal time (UTC, the acronym is ordered differently from what it means), which is standard time based on time in Greenwich, London.

Universal time is calculated using a time offset (in minutes, when in JavaScript). This offset is based on the time zone configured in the client browser operating system.

If you plan on storing dates for users in multiple time zones, this is what you should use.

0
source share

In addition to Dan, the notion that the acronym is different from what it stands for is a good reason: Reduction in UTC on Wikipedia

0
source share

All Articles