Date and time functions in PHP. The time () function is used to obtain the current timestamp. the date () function format the timestamp from 00:00:00, January 1, January 1, 1970. Does anyone know how he formatted it? For example, if I have a timestamp, can I calculate the time by myself? The timestamp obtains the sum of seconds. However, I tried the date and time functions in PHP.
The time () function is used to obtain the current timestamp from 00:00:00, January 1, January 1, 1970.
The date () function is used to format the timestamp. Does anyone know how he formatted it? For example, if I have a timestamp, can I calculate the time by myself? The timestamp obtains the sum of seconds. However, I tried to divide the timestamp by 60 or equal to the minute. If we divide the hour by 60 and divide the hour by 24, why is that incorrect?
------ Solution --------------------
The author said that the acquisition timestamp is divided by the day's 24 hours to get the number of days plus 1970
Obtain the current time.
The problem is 365 days a year or 366 days?
Just as if you get the month directly, 28 days a month, 31 is also a month!
------ Solution --------------------
The number of seconds can only be counted as days. Because of the existence of a leap year, it cannot be simply obtained.
------ Solution --------------------
Function todate ($ time) // Convert time to date
{
$ Arr = getdate ($ time );
Echo $ arr [year], "year", $ arr [mon], "month", $ arr [mday], "Day", $ arr [hours], "hour", $ arr [minutes], "minute", $ arr [seconds], "second ";
}
Perfect solution
------ Solution --------------------
PHP code
Function todate ($ time) // Convert the time to date {$ arr = getdate ($ time); echo $ arr [year], "year", $ arr [mon], "Month", $ arr [mday], "Day", $ arr [hours], "hour", $ arr [minutes], "minute", $ arr [seconds], "Seconds ";}