In php, if you want to convert a date to a timestamp, you can directly use the strtotime function. If you want to convert a timestamp to a date, you can directly use the date () function, next I will introduce them to my friends.
The strtotime () function parses the datetime description of any English text into a Unix timestamp.
Example
The Code is as follows: |
Copy code |
<? Php Echo (strtotime ("now ")); Echo (strtotime ("3 October 2005 ")); Echo (strtotime ("+ 5 hours ")); Echo (strtotime ("+ 1 week ")); Echo (strtotime ("+ 1 week 3 days 7 hours 5 seconds ")); Echo (strtotime ("next Monday ")); Echo (strtotime ("last Sunday ")); ?> Output: 1138614504 1128290400 1138632504 1139219304 1139503709 1139180400 1138489200 |
In the preceding exampleConvert a date to a timestampNow, we can also convert it to a timestamp, for example, 2013-04-21.
The Code is as follows: |
Copy code |
$ A = date (); $ Mk = strtotime ($) |
It is required that you only send text messages between-in the daytime. How can you get the daily time range?
The Code is as follows: |
Copy code |
<? $ Y = date ("Y", time ()); $ M = date ("m", time ()); $ D = date ("d", time ()); $ Start_time = mktime (9, 0, 0, $ m, $ d, $ y ); $ End_time = mktime (19, 0, 0, $ m, $ d, $ y );
$ Time = time (); If ($ time >=$ start_time & $ time <= $ end_time) { // Do something .... } ?> |
Next we will introduceTimestamp to date
Date () function,
This function not only obtains various time and date types, but also supports date conversion calling.
The Code is as follows: |
Copy code |
<? $ Time = time (); $ Date = date ("Y-m-d", $ time ); Echo 'www. bKjia. c0m prompt '. $ date ?> |
In this way, the www. bKjia. c0m prompt 2013-04-21 is output.