In php, the date function can directly convert the timestamp into a date. Of course, there are some other methods. I won't talk much at the beginning of the article to avoid getting more and more difficult to understand, let's take a look at some examples. In php, the date function can directly convert the timestamp into a date. Of course, there are some other methods. I won't talk much at the beginning of the article to avoid getting more and more difficult to understand, let's take a look at some examples.
Script ec (2); script
Current Timestamp
The Code is as follows: |
|
$ Nowcode = time (); $ Nowcode = strtotime (now ); |
Time stamp converted to date
The Code is as follows: |
|
$ Date = date ("Y-m-d", getdatecode ($ )); |
Convert date to Timestamp
The Code is as follows: |
|
Function getdatecode ($ time) { $ Year = (int) substr ($ time,); // obtain the year $ Month = (int) substr ($ time, 5, 2); // obtain the month $ Day = (int) substr ($ time, 8, 2); // obtain the number of digits Return mktime (, 0, $ month, $ day, $ year); // returns the UNIX timestamp. }
|
Well, let's get down to the truth and convert 1228348800 to the format Code as follows:
The Code is as follows: |
|
$ Date3 = date ('Y-m-d H: I: s', "1228348800 "); |
This is OK. If you still want to get the hour and minute, you only need to change 'Y-m-d'. But pay attention to it, PHP time also has an error of 8 hours. add OK.
You can add
The Code is as follows: |
|
Date_default_timezone_set ("Asia/Shanghai ");
|
Below are moreTimestamp conversion dateExample
The Code is as follows: |
|
(1) print the timestamp strtotime ("+ 1 day") at this time tomorrow. Current time: echo date ("Y-m-d H: I: s", time () Result: 09:40:25 Time specified: echo date ("Y-m-d H: I: s", strtotime ("+ 1 day") Result: 09:40:25 (2) print the PHP timestamp strtotime ("-1 day") at this time yesterday. Current time: echo date ("Y-m-d H: I: s", time () Result: 09:40:25 Time specified: echo date ("Y-m-d H: I: s", strtotime ("-1 day") Result: 09:40:25 (3) print the timestamp strtotime ("+ 1 week") for the next week. Current time: echo date ("Y-m-d H: I: s", time () Result: 09:40:25 Time specified: echo date ("Y-m-d H: I: s", strtotime ("+ 1 week") Result: 09:40:25 (4) print the timestamp strtotime ("-1 week") for the last week. Current time: echo date ("Y-m-d H: I: s", time () Result: 09:40:25 Time specified: echo date ("Y-m-d H: I: s", strtotime ("-1 week") Result: 09:40:25 (5) print the specified PHP timestamp strtotime ("next Thursday") for the next week. Current time: echo date ("Y-m-d H: I: s", time () Result: 09:40:25 Time specified: echo date ("Y-m-d H: I: s", strtotime ("next Thursday") Result: 00:00:00 (6) print the timestamp strtotime ("last Thursday") of the specified last week. Current time: echo date ("Y-m-d H: I: s", time () Result: 09:40:25 Specified Time: echo date ("Y-m-d H: I: s", strtotime ("last Thursday") Result: 00:00:00 |
To sum up, all the above examples of time Stamp conversion date show that the above three functions are converted to the strtotime (), date (), time () functions, if you want to know its usage, you can search for it on this site.