DEV Community

Cover image for What is "the time"? ⏳ ...and what is meant by UTC in date.toUTCString()?

Posted on

What is "the time"? ⏳ ...and what is meant by UTC in date.toUTCString()?


Pretty much in all major programming languages there's support for working with dates and times. JavaScript for instance, has a Date class for this purpose, and this class has many methods. Among all of these methods though, one is toUTCString(), which I happened to have encountered a million times, and yet had no clear understanding of it (well, of course, before Googling and writing this article).

Checking its documentation on the MDN first, we'll see:

The toUTCString() method converts a date to a string, interpreting it in the UTC time zone.

Hmm... so UTC is a time zone! Just like Greenwich (GMT), so let's Google it to see how it's different from GMT:

Coordinated Universal Time or UTC is the primary time standard by which the world regulates clocks and time.

Well, but that sounds a lot like GMT!?

So I Google GMT vs UTC next:

Prior to 1972, this time was called Greenwich Mean Time (GMT) but is now referred to as Coordinated Universal Time or Universal Time Coordinated (UTC).

Hmm... that's odd! It cannot be just about a "rename"!

What is the difference between GMT and UTC really?

Although this is not a coding question, programmers bump into it pretty often, so a non-programming and easy to understand answer to it would be worthy.

In simple terms, we can assume that both GMT and UTC are "clocks" that tell us "the time", however, UTC is the more precise one, so it took GMT's place in our measurement of the time around the world (in 1972).

But wait, what does "a more precise clock" mean at all? To understand this, we need to understand what "the time" itself really is in the first place!

What is "the time? ⏳🔮

Time (in its today's form, i.e., months, days, hours, minutes, etc.) is a human-made thing, and is our "means of measuring the passage of events". Say you're planning a programming event next month. What is next month? So you need to have an a shared and wide-spread understanding of the time (the amount of the passage of the events) we all consider "next month"!

Our today's shared understanding of "the time" is the result of a convention/agreement our ancestors left for us: They searched for some regularly recurring event, and they initially found it in the change of day to night, and in the change of seasons. (If you notice, these are astronomical events, i.e., rotation of the earth around its own axis, and sun's position in the sky. This is what the GMT clock (timezone) uses to measure the time). But there was still room for improvement:

The measurement of time began with the invention of sundials in ancient Egypt some time prior to 1500 B.C. However, the time the Egyptians measured was not the same as the time today's clocks measure. For the Egyptians, and indeed for a further three millennia, the basic unit of time was the period of daylight. source

So basically, you could tell someone "I'll see you tomorrow", but you couldn't tell them "I'll see you tomorrow at 7:30"! :D

Donald Duck Vintage Time-in Gif Image via Giphy

So the next [obvious] step for them was to make their measurement of the time more precise, and as a result, they agreed (not surprisingly) to divide each full day into 24 parts, aka "hours", and they agreed to divide each hour into 60 minutes, and so on. So today you have something called "a clock" that allows you "to universally keep your understanding of every point of the past, of the current and of the future events in sync with others", therefore you can happily plan your event next month, without an issue (well, without a "temporal issue" at least!) 🕙🕜🕞.

Why was UTC needed then? UTC was needed for the exact same reason, it was a further step in this interminable road towards our unquenchable thirst for more and more precision. As we've said above already, GMT used some not-stable-enough astronomical events to tell us the time, i.e., events not as precisely regular as we expect to set as the basis of our modern agreement for measuring the time.

Don't get me wrong, actually, the GMT clock is still good enough for numerous purposes, but it's just like a ruler that measures in units only as small as millimeters, while we need greater length precisions as well definitely once we get into realms like engineering, science and so on.

Here's where UTC comes in wonderfully. UTC measures "frequency of an atom's vibration" (*), and that happens to be a much more stable and regularly recurring event compared to things like earth's rotations or sun's position in the sky. Indeed, we're talking about 1 billionths of a second per day v.s up to a few minutes per day! So no wonder UTC can keep us in sync in a much more reliable way.

High Five Bro with Cat Gif - via giphy

That's it, ...for the most part! If you're a curious mind, there's still one more delicate (and important) point we've missed to mention here. If you think about it, UTC is great in terms of its precise measuring of the time, however, it also creates a (minor) issue: We actually do care about what a full day is! This is regardless of how we measure the time! No matter how accurate a clock is, no matter how precisely it keeps us in sync to each other, we do not like it to make our days dark and to make our nights bright! (with a bit of exaggeration). So we need to occasionally adjust the UTC clock, and this is exactly what we do, using a second aka a "leap second" to . From Wikipedia:

A leap second is a one-second adjustment that is occasionally applied to Coordinated Universal Time (UTC), to accommodate the difference between precise time (International Atomic Time (TAI), as measured by atomic clocks) and imprecise observed solar time (UT1), which varies due to irregularities and long-term slowdown in the Earth's rotation.

- (*) Disclaimer: I'm neither a Physicist nor an Astronomer, and these topics are very complicated, so this answer should have some inaccuracies naturally. If you need a deeper and more accurate understanding, read further in this answer on Physics Stack Exchange.
- Cover Image from Unsplash by Lukas Blazek.

Top comments (0)