"PHP" Date Time

Source: Internet
Author: User
Tags time zones

I. Date and time:
A) This is a very important piece of content, we are in Windows, or in the future to contact the timer, we need to use this piece of content!
Ii. date and time in PHP:
A) Timestamp: time () can get timestamp
I. Time stamp it's an integer!
II. Range: 2147483648 ~ 2147483647
III. Definition: On January 1, 1970, in Greenwich, England, it was officially opened, starting from 0 seconds to an integer value.
b) Time zone: (Search Date_default_timezone_set in PHP manual (' time Zone ');)
I. There are 24 time zones in the world, China belongs to the East Eight district
Ii. If the time zone is not specified in PHP, the UK time zone is automatically selected
Iii. How to set the time zone:
1.date_default_timezone_set (");
2. Note: Use the time zone setting function above to choose a region of China can be a time conversion! Because China belongs to the East Eight district!
3. Set the time zone in php.ini
A) Search: Date.timezone = "UTC"; Change to "PRC"
iv. UTC = United Kingdom of Great Britain and Northern Ireland (United Kingdom)
V.PRC = People's Republic of China
Three, date time function:
A) time () Gets the current system timestamp
b) Date () format a timestamp

1 //formatting the current timestamp2 Date(' Y-m-d h:i:s ', Time())3 4 //calculate the time stamp of yesterday5 $yestoday= Time()-24*60*60;6 7 //calculate the time stamp of the present time yesterday8 Date(' Y-m-d h:i:s ',$yestoday);9 Ten //calculate the time stamp of the current time last year One Date(' Y-m-d h:i:s ', Time() -24*60*60*365);

c) mktime () get a timestamp for a specified date

1 // mktime () generates a timestamp of a specified date   mktime (hour, minute, second, month, day, year); 2 $birthday Mktime (0,0,0,30,5,1991);

d) strtotime () converts a date in a string format to a timestamp

1 //gets the timestamp of the string type2 Var_dump(Date(' Y-m-d h:i:s ',Strtotime(' Now ')));3 Var_dump(Date(' Y-m-d h:i:s ',Strtotime(' Yesterday ')));4 Var_dump(Date(' Y-m-d h:i:s ',Strtotime(' Ten September 2000 ')));5 Var_dump(Date(' Y-m-d h:i:s ',Strtotime(' +1 Day ')));6 Var_dump(Date(' Y-m-d h:i:s ',Strtotime(' +1 Week ')));7 Var_dump(Date(' Y-m-d h:i:s ',Strtotime(' +1 Week 2 days 4 hours 2 seconds ')));8 Var_dump(Date(' Y-m-d h:i:s ',Strtotime(' next Thursday ')));9 Var_dump(Date(' Y-m-d h:i:s ',Strtotime(' last Monday '));

"PHP" Date Time

Related Article

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.