Convert between PHP timestamp and date_PHP Tutorial
WBOYOriginal
2016-07-13 17:15:13997browse
In PHP, if we want to convert a date into a timestamp, we can directly use the strtotime function. If we want to convert a timestamp into a date, we can directly use the date() function. Let me introduce it to my friends.
strtotime() function The strtotime() function parses the date-time description of any English text into a Unix timestamp.
date into a timestamp . We can also convert such as 2013-04-21 into a timestamp
The code is as follows
Copy code
$a = date();
$mk = strtotime($a)It is required that text messages can only be sent between 8:00-20:00 during the day. How can I get this time range every day?
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 introduce how to convert time timestamp into date
date() function,
This function can not only obtain various times and dates, but also perform date conversion
The code is as follows
Copy code
<🎜>
$time = time();<🎜>
$date = date("Y-m-d",$time);<🎜>
echo 'www.bKjia.c0m prompt'.$date<🎜>
?>
This will output www.bKjia.c0m prompt 2013-04-21.
http://www.bkjia.com/PHPjc/628855.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628855.htmlTechArticleIn php, if we want to convert date into timestamp, we can directly use the strtotime function. If we convert the timestamp into The date can be implemented directly using the date() function. Let me give you...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn