In PHP I want to get a timestamp there are many ways, the most common is to use the time function and the strtotime () function to convert the date into a timestamp, I would like to share the time stamp function strtotime usage.
gets the specified date of year into the timestamp:
php timestamp function gets the UNIX timestamp of the specified date strtotime (' 2012-12-7 ')
examples are as follows:
Copy Code code as follows:
<?php echo strtotime (' 2012-12-7 '); Results: 1354838400?>
Description: Returns the December 7, 2012 0:0 0 seconds timestamp.
converts the current year to time stamp: The PHP timestamp function gets the Unix timestamp of the current date,
examples are as follows:
Copy Code code as follows:
<?php Echo $time =intval (Time ());?>
: Returns the time stamp of a minute and a minute on the current date.
converts the timestamp to month Day:
Copy Code code as follows:
<?php
echo Date ("Y-m-d h:i:s", Intval (Time ()));
?>
Case
Copy Code code as follows:
<?php
/*
From:http://www.jb51.net
@date: 2013-02-22
*/
Echo Strtotime ("Now"), "n";
Echo Strtotime ("September"), "n";
Echo strtotime ("+1 Day"), "n";
Echo strtotime ("+1 Week"), "n";
Echo strtotime ("+1 Week 2 days 4 hours 2 Seconds"), "n";
Echo Strtotime ("next Thursday"), "n";
Echo Strtotime ("Last Monday"), "n";
?>
php timestamp function to get English text date time
facilitates comparison by using date to convert a timestamp to a system time with a specified timestamp
(1) Print the timestamp strtotime ("+1 Day") at this time tomorrow
Current time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("+1 Day") Results: 2009-01-23 09:40:25
(2) Prints the timestamp strtotime ("-1 day") at this time yesterday
Current time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("1 day")) Results: 2009-01-21 09:40:25
(3) Print the timestamp strtotime ("+1 Week") at this time next week
Current time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("+1 Week")) Result: 2009-01-29 09:40:25
(4) Prints the timestamp strtotime ("-1 week") at this time last week
Current time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("-1 Week")) Results: 2009-01-15 09:40:25
(5) Prints the timestamp strtotime ("next Thursday") that specifies the next day of the week
Current time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("next Thursday")) Result: 2009-01-29 00:00:00
(6) Prints the timestamp strtotime ("last Thursday") that specifies the previous week
Current time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("last Thursday")) Result: 2009-01-15 00:00:00
above PHP timestamp function example know the source sky, Strtotime can be any English text of the date and time description of the Unix timestamp, we combine the mktime () or date () format date time to get the specified timestamp, to achieve the required date time.
you may be interested in the article