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 ."
";