Time and Date Manipulation
Learn about the UNIX epoch and how to manipulate dates and times.
We'll cover the following
Working with times and dates can be tricky in programming languages. For this reason, most languages have some sort of built-in Date
object that helps to make the process easier. JavaScript is no exception, and we’ll be taking a look at how that works.
The UNIX epoch
The UNIX epoch is an arbitrary date of January 1, 1970 which is used in programming as a reference point in time from which to measure dates. This allows dates to be expressed as an integer that represents the number of seconds since the epoch. As we can imagine, this produces some very large numbers, and there’s a potential problem looming in 2038 when the number of seconds since the epoch will be greater than
Times and dates
Date
objects contain information about dates and times. Each object represents a single moment in time.
In JavaScript, we can use a constructor function to create a new Date
object using the new
operator. Try entering the following code:
Get hands-on with 1200+ tech skills courses.