E.R.MCLAIN

The Date Object

23 April 2020

Objects are a vital concept in programming, and languages such as Javascript revolve entirely around them, and as such are aptly described as object-oriented programming. Objects are used to represent collections of data, just as a real-life object has many different qualities to it, such as size, model, or color. However, unlike real-life, in programming objects can also be used to represent abstract concepts that aren't something that can be simply held or viewed the way we would picture an object. This is the case with date and time, the familiar yet essential invention that allows us to plan and coordinate our daily existence.

Dates are tracked by their distance from the specific agreed upon moment that marks the beginning. For example, the year we live in (2020 as I am writing) is simply the number of years passed from the year of 1 CE, also known as 1 AD, and we are two thousand and twenty years deep into the common era. Dates can of course be counted from earlier as well, and any time preceding 1 CE is considered negative, stretching back infinitely as the BCE.

This same concept exists and allows us to calculate time in programming, however there is a distinction. In programming languages an entirely different, considerably more recent date is used as the special point by which we measure where we are currently. This date is called Unix time, and we represent the precise time by counting the milliseconds that have elapsed since midnight on the first of January 1970.

The specific type of code that tracks time in computer programs is called the date object. The Javascript code that allows us to represent the current moment is this:

 new date() 

However, we can also be more specific with our request in terms of the way which the time is displayed. We can retrieve a specific component of the date, or specify parameters for how the date will be displayed.

getMinutes()
new Date(timestamp)
getUTCFullYear()

This code above is just a small sampling of the many types of methods there are to work with time in Javascript.