Time Functions in PHP

Source: Internet
Author: User
When I learned how to use PHP, I encountered a small problem, that is, obtaining the time of the previous hour, and some people's code was a bit cool. In the past, when taking the time in shell, I used the date command directly. I thought there may also be class functions in PHP. I asked my classmates and shared the results with you. In PHP, when time is used, the function is

When I learned how to use PHP, I encountered a small problem, that is, obtaining the time of the previous hour, and some people's code was a bit cool. In the past, when taking the time in shell, I used the date command directly. I thought there may also be class functions in PHP. I asked my classmates and shared the results with you. In PHP, when time is used, the function is

When I learned how to use PHP, I encountered a small problem, that is, obtaining the time of the previous hour, and some people's code was a bit cool. In the past, when taking the time in shell, I directly used the date command. I thought PHP may also have a similar function. I asked my classmates and shared the results with you.

In PHP, when time is used, the function is: date. If I want to get the time of the previous hour, and the format is YYYYmmdd: HH, that is, the format, how can I use it?

Strtotime (). You can use the current time as the coordinate to get a time and store it in an integer. Then, if you want a specific format, use this integer to convert the format. Let's look at the following small example:

$ Timestamp = strtotime ("-1 hour ");
$ Str = date ("Ymd: H", $ timestamp); // Y: four-digit m: 00-12 d: 00-31 H: 00-23

For specific functions, see the description of the date function.


Echo $ str ."
";

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.