Repository navigation
003 Working with TIME
OK, time is a very deep topic and needs that you understand UNIX timestamp and UTC time.
This a POINT in time and is shown in seconds since 1970/1/1. This does not take into account calendar nor different time zones. It is useful when you have $time_start and $time_end and you want to know difference between START and END. UNIX time stamp does not take into account leap seconds caused by Earth's trajectory changes caused by gravity. In 2016 1 second was added to UTC time, but in UNIX timestamp it is blank.
This can also go into negative values, which means that the event is before 1970/1/1. And 32 bit systems will run out of numbers they can display in 2038! But 64 bit systems can keep counting seconds for billions of years into the past/future.
time() does not take in any arguments and gives back UNIX timestamp in seconds. This function gives back INT.
date() takes in two arguments $date_or_time_format = 'Y-n-j H:i:s'; and $unix_timestamp = 1791986362; date('H:i:s', $unix_timestamp);
strtotime() helps to convert human readable time strings into UNIX timestamps, it gives back INT or FALSE (if PHP cannot understand the string). It can also understand some basic English like '10 days ago' or 'tomorrow' etc. strtotime('2026/9/14'); gives this unix timestamp: 1789344000.
- It is base for calculating time zone differences
- It is situated in London, London time is UTC time (in winter) but UTC+01:00 in summer.
- JPN has only one time zone and can be set like this
date_default_timezone_set('Asia/Tokyo'); - It is adjusted for leap seconds
- MySQL also uses this as a base for time calculations
- Calendar date/time related calculations should all use UTC time, then it is very easy to calculate time zones and calendars will be automatically adjusted for leap year.