That sounds like a simple question, but you’d be surprised at how complex the infrastructure provides you with an accurate time. When your users exist across time zones or even travel across time zones while using your systems, there’s an expectation that everything works seamlessly.
But it’s not simple.
Example: You have an employee in Phoenix who needs to schedule an email for 8:00 AM on Monday for his company in Los Angeles. Phoenix doesn’t adjust for daylight savings time; Los Angeles does. And what about the recipients? Should they receive the email at 8:00 AM on Monday in their respective time zone? Or will subscribers in New York receive their email at 11:00 AM EST on Monday?
How Time Is Displayed On Your Computer
Operating System (OS) – Your operating system looks up the time from its real-time clock (RTC). It adjusts the format of the date for your locale and the time for your appropriate time zone, typically determined by the location of your device.
Date Formats – There are several common date formats, including:
The Gregorian calendar date (YYYY-MM-DD), e.g. 2022-02-08
The United States style date (MM/DD/YYYY), e.g. 02/08/2022
The European style date (DD/MM/YYYY), e.g. 08/02/2022
Time Zones – There are 24 time zones in the world, each roughly 15 degrees of longitude apart from the other. Time zones divide the world into regions with the same standard time so that people in each time zone can have a common time for their daily activities.
Daylight Saving Time – In regions that observe Daylight Saving Time, clocks are set forward by one hour in the spring and back by one hour in the fall. This results in an extra hour of daylight in the evenings during the summer months, but it also means that the sun rises and sets an hour earlier in the mornings and evenings, respectively, during the winter months.
Real-Time Clock (RTC) – your computer maintains the time, even when turned off, using a chip known as the RTC. When it’s not powered, a small lithium battery keeps the chip ticking (pun intended) and can power it for up to a decade without charge.
Network Time Protocol (NTP) – when operating systems have an established connection to the internet, they use NTP to synchronize their clocks with a pool of time servers, including those provided by Network Time Protocol. By default, Windows synchronizes with NTP servers once every 7 days, while macOS synchronizes once every hour. NTPs maintain their time using coordinated universal time (UTC). When a client requests the current time from an NTP server, the server responds with a 64-bit value representing the number of seconds since January 1, 1900, at 00:00:00 UTC.
Coordinated Universal Time (UTC) – a standardized time used as the basis for all timekeeping in the world. It is based on the International Atomic Time (TAI), which measures the average time elapsed between two specific points in the orbits of Earth’s moon. UTC was first implemented in 1972 as a successor to TAI and Greenwich Mean Time (GMT). UTC is kept within 0.9 seconds of the TAI time scale, and its accuracy is maintained by the use of atomic clocks and other timekeeping technologies.
The 24 UTC time zones are divided into offset categories where each offset is the adjustment for the appropriate time in hours: UTC-12, UTC-11, UTC-10, UTC-9, UTC-8, UTC-7, UTC-6, UTC-5, UTC-4, UTC-3, UTC-2, UTC-1, UTC, UTC+1, UTC+2, UTC+3, UTC+4, UTC+5, UTC+6, UTC+7, UTC+8, UTC+9, UTC+10, and UTC+11.
International Atomic Time (TAI) – a time standard that is based on the average time elapsed between two specific points in the orbits of Earth’s moon. TAI is one of the most accurate and stable time scales available, and it is maintained by the International Bureau of Weights and Measures.
Atomic Clocks – are highly accurate timekeepers that use the natural vibrations of atoms to measure time. The most common type of atomic clock is the cesium atomic clock, which uses the vibrations of cesium atoms to keep time. The accuracy of an atomic clock is maintained by the stability of the frequency of the electromagnetic radiation emitted by the cesium atoms. This frequency is so stable that it only changes by a fraction of a second over thousands of years. The frequency of the electromagnetic radiation is then compared to a quartz oscillator, which is used to control a counter. The counter counts the number of cycles of electromagnetic radiation, and this count is used to calculate the time. The counter is constantly corrected to ensure that it remains in sync with the vibrations of the cesium atoms.
Modern systems often record times as Unix Timestamps. A Unix timestamp is a numerical representation of a specific point in time, measured as the number of seconds that have elapsed since January 1, 1970, at 00:00:00 UTC. Unix timestamps are widely used in computer systems because they are simple to work with and can easily be compared, sorted, and manipulated. They are also independent of time zones, which means that they provide a standardized representation of time that can be used across different geographic regions.
So… when you check the time, you’re displaying
Working With Dates In PHP
I’ve written before about how to programmatically display the year for your copyright declaration so that you don’t have to keep updating it every year. There’s a ton more that you can do with dates, though. Here are some examples:
Display the date as 2023-02-08:
$current_date = date(“Y-m-d”);
echo $current_date;
Display the date as a timestamp 1612684800:
$timestamp = strtotime(“2023-02-08”);
echo $timestamp;
Display the date and time formatted in UTC instead of the local time zone as 2023-02-08 15:25:00:
$utc_date = gmdate(“Y-m-d H:i:s”);
echo $utc_date;
Display the current Unix timestamp as 1612742153:
$current_timestamp = time();
echo $current_timestamp;
Default the time zone to Los Angeles and then display the date and time as 2023-02-08 07:25:00:
date_default_timezone_set(“America/Los_Angeles”);
$date = date(“Y-m-d H:i:s”);
echo $date;
Organizing the PHP date format characters into logical groups, with each group in alphabetical order and the format characters as sub-bullets:
Day
d – Day of the month, 2 digits with leading zeros (01 to 31). Example: 15
D – A textual representation of a day, three letters (Mon through Sun). Example: Thu
j – Day of the month without leading zeros (1 to 31). Example: 15
l (lowercase ‘L’) – A full textual representation of the day of the week (Sunday through Saturday). Example: Thursday
S – English ordinal suffix for the day of the month, 2 characters (st, nd, rd or th). Example: th
w – Numeric representation of the day of the week (0 (for Sunday) through 6 (for Saturday)). Example: 4
z – The day of the year (starting from 0). Example for current date might not be accurate without exact calculations.
Month
F – A full textual representation of a month (January through December). Example: February
m – Numeric representation of a month, with leading zeros (01 to 12). Example: 02
M – A short textual representation of a month, three letters (Jan through Dec). Example: Feb
n – Numeric representation of a month, without leading zeros (1 to 12). Example: 2
t – Number of days in the given month (28 through 31). Example: 28
Week
W – ISO-8601 week number of year, weeks starting on Monday (Example: 42, the 42nd week in the year). Example for current date might not be accurate without exact calculations.
Year
o – ISO-8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. Example: 2024
Y – A full numeric representation of a year, 4 digits. Example: 2024
y – A two-digit representation of a year. Example: 24
Timezone
T – Timezone abbreviation. Example: EST
e – Timezone identifier. Example: America/New_York
P – Difference to Greenwich time (GMT) with a colon between hours and minutes. Example: -04:00
O – Difference to Greenwich time (GMT) without colon between hours and minutes. Example: -0400
Z – Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. Example: -14400 (for EST)
Every language has its functions to work with UTC, timestamps, display formats, time zones, and daylight savings time. If you’re developing a platform, you’ll want to pay a lot of attention to how you’re storing time-based data as well as how you’re formatting and displaying it. If you’re a business, you’re going to want to ensure your platforms can manage working across time zones, display the appropriate formats for your users, as well as manage daylight savings time adjustments.
So… What Time Is It?
My operating system is formatting the date and time as Feb 15, 2024, 5:32 AM. The time has been adjusted from a Unix Timestamp to my time zone, adjusted for Daylight Savings Time. That time has been synchronized in the last hour from MacOS with an NTP server that is in UTC and adjusted to keep within 0.9 seconds with TAI and the atomic clocks. All of this, of course, is an accurate time provided for my location with respect to the Earth, Moon, and Sun… adjusted for Daylight Savings Time.
©2024 DK New Media, LLC, All rights reserved.
Originally Published on Martech Zone: What Time Is It? How Our Systems Display, Calculate, Format, and Synchronize Dates and Times