Date and time functions in PHP

Source: Internet
Author: User
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 ";}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.