Date/Time
In short: A data type or class for representing and processing date and time values — the basis for everything from timestamps to calendar calculations.
In more detail: Modern languages usually offer immutable date/time objects, where every “change” (e.g. adding a day) creates a new object instead of changing the existing one — this avoids subtle bugs from accidentally shared, mutated objects. Timezones are a common source of error here, which is why many systems consistently work with UTC internally and only convert to the local timezone at display time.
In Depth
Date/time processing is rightly considered one of the most error-prone standard topics in software development — the cause lies less in the code itself than in the messiness of the real world: different timezones, daylight saving time changes, leap years, different calendar systems, and inconsistent date formats between countries (day/month/year vs. month/day/year).
from datetime import datetime, timezone
now_utc = datetime.now(timezone.utc) # always unambiguous, independent of the server locationThe most important basic rule of modern systems: always store UTC internally, only localise at display time. UTC (Coordinated Universal Time) has no daylight saving time and no regional shifts — a UTC timestamp is always unambiguous, no matter where in the world it’s created or read. If local time were stored instead, subtle bugs arise: the same time of day can occur twice during a daylight-saving transition (when clocks go back) or not exist at all (when clocks go forward), and a server in a different timezone than the users misinterprets stored values.
The second important point is immutability:
date1 = today()
date2 = date1.plusDays(7)
// date1 stays UNCHANGED, date2 is a new, independent objectOlder date APIs (e.g. java.util.Date in early Java versions) were mutable — a method could directly modify the passed date object. This led to hard-to-find bugs when an object was referenced in several places in the code and one place unexpectedly changed it, which then showed up everywhere else. Modern APIs (Java’s LocalDate/Instant, Python’s datetime when used correctly) instead return a completely new object on every “change”, the original is guaranteed to stay untouched — the same basic principle as with strings.
See also: Non-primitive Types