# JavaScript — What The Heck is UTC and Why You Need to Know This

## An explanation of UTC, time zone, and Date object

Jan 3 · 6 min read

Everybody who is reading this post must have used Date object in JavaScript or used a library for converting date times. When I was so much more unfamiliar with Date, I didn’t know what UTC is and why I should care about it. Don’t you have the same feeling and thoughts about it? In this post, I will talk about the Date as the following contents.

• What is UTC
• Date in JavaScript
• Open-source libraries on Date

# What is UTC

Back in the 18th century, when the train was invented, people had been using local time. They set up the clock to noon when the sun is at its highest height in the sky. Once mankind started to be able to move a long distance by trains, the time often confused them. They soon wanted a new standard time.

In the 19th century, a group of people who are on behalf of their countries gathered and compromised that they need something new for the standard time. They decided Greenwich in England to be the center of the standard time zone and divided the earth into 24 areas, which has 15 longitudes. So this became the current 24-hour system.

`24 areas x 15 longitudes = 360 deg`

They decided to call the standardized time Coordinated Universal Time. Then shouldn’t it be CUT? The English speakers originally proposed CUT for Coordinated Universal Time, but the French speakers used TUC, temps universel coordonné. So they compromised to call it UTC.

Then let’s talk about 24 areas with 15 longitudes for each area stuff.

# Time Zone

What does it mean to divide the world map into 24 areas? The point of where the time zone that many countries use nowadays is located in Greenwich, a small town in London, England.

Here’s the prime meridian where every time starts from. It’s the vertical line on the globe where the longitude is 0° — it is Greenwich. The area, time zone, is the area 15°E longitude to East and 15°W longitude to West from the prime meridian. That’s the closest time zone to the prime meridian. If you go little more to East, then the new time zone is from 7.5°E longitude to East to 22.5°E longitude to East. In contrast, if you go to the Westside, the new time zone is from 7.5°E longitude to 22.5°E longitude. South Korea, where I’m from, is at 127.7°E longitude.

Then what happens when you move 15° longitude to East or West? Like I mentioned earlier in this post, there are 24 areas, which are 24 time zones. Each time zone has 7.5°W and 7.5°E as a range. Thus, if you move 15° longitude to either East or West, it means your time zone is changed by 1 hour. You can represent this using UTC with `+` or `-` . The time zone that has the prime meridian is `UTC+0`. The time zone 7.5°E — 22.5°E is `UTC+1` and 7.5°W — 22.5°W is `UTC-1`.

Let’s say it’s 8 pm in Greenwich in which the prime meridian is, and you want to head Iran at 45°E longitude. And it takes 5 hours. What time would it be in South Korea by the time you get there?

`Date of departure: 21thTime for departure: 8 pmFlight time: 5 hrTime zone change: 3`

The flight takes 5 hours. It will be 1 am on 22th in the prime time zone. And the time zone should be moved towards East by 3 zones. Every time your time zone is changed to the Eastern one, your time gets 1 hour. So, it will be 22th 4 am in Iran by the time you arrive.

`8 pm(21th) + 5 hr + 3 hr(time zone)~~~~~~~~~~~22th 1am                   ~~~~~~--> 22th 4am`

# The Boundary of Time Zone

Even if you move to the East or West continuously, you can’t gain or lose time forever. Since the globe is a sphere, each edge of the time zone meets on the other side of the prime meridian, where the longitude is 180° to both sides.

Suppose you depart at 7 am on 11th, at 135°W longitude. And you want to move towards West by 75° longitude. Then the time zone will be changed as follows.

`Initial: 135°W, 7 am, 11th1st move: 135°W → 150°W. 6 am2nd move: 150°W → 165°W. 5 am3rd move: 165°W → 180°W. 4 am 12th(+1)4th move: 180°W → 165°E. 3 am5th move: 165°E → 150°E. 2 am`

The date is changed at 180° longitude.

All you should be careful about is that the date is changed at 180° longitude. If you were heading West, the date is going to be a day faster, if you were heading the other side, the date is going to be a day later.

In addition, many countries use GMT which is a time zone in Greenwich. But, some countries like the U.S.A that has Daylight Saving Time, they switched the time zone to a special one, such as DST for Daylight Saving Time.

# Date Object in JavaScript

Date object in JavaScript is a good helper API for developers. It’s very useful when you get the local time or the UTC time.

This method returns a numeric value of the specified date that you passed into the Date constructor, since January 1, 1970, 00:00:00 UTC. If you don’t pass any arguments to the constructor, it uses the default date, which is now.

There is an opposite method, Date.prototype.getDate. If you call getDate, it gives you the hour of the specified date, while getUTCHourse gives you a UTC time. This actually could make a difference.

getHours returned 18 and getUTCHours returned 9. The time where I’m now is `UTC+9`. That’s why getHours gave me 18, which is 9 hours faster than `UTC+0`.

If the users of your app are only staying in the country, then theoretically, you wouldn’t have to consider UTC time.

# Conclusion

Each time zone has a 15° longitude range, 7.5°W and 7.5°E from the meridian. The date is changed every time the time zone is switched. If it switched to the Western zone, the time loses by 1 hour, and if it’s to the Eastern zone, the time gets an hour.

Understanding the time zones is important for when you have to deal with the dates. I hope you read other posts as well to harden your understanding!

Written by

Written by