How long does the time function work in php

The php date () and time () function works between 1901-2038. What function will I use for my long-term projects. or I'm wrong?

+3
source share
2 answers

The timestamp only wraps after January 19, 2038 on 32-bit systems. On 64-bit systems, this is not a problem, since most 64-bit operating systems use signed 64-bit integers to store the timestamp. (With signed 64-bit integers, the timestamp wraps around December 4, 292,277,026,596 AD.)

By 2038, I would say that most computer systems will run on 64-bit architecture (at least), so this is probably not going to be a problem in the long run. In addition, there is nothing you can do about it - this is a problem with the underlying operating system and processor architecture, and not with the code you write.

+6
source

You can always use the PEAR :: Date class , it can be used for dates before 1970 and after 2038 .

Example:

require_once 'Date.php';

$longAgo = new Date('1813-02-23T05:34:23');

echo $longAgo->getTime();
echo $longAgo->getDate();

Perhaps also a DateTime class can ?

0
source

Source: https://habr.com/ru/post/1723332/


All Articles