One, the PHP timestamp function gets the UNIX timestamp of the specified date Strtotime ("2009-1-22″) example is as follows:
Echo strtotime ("2009-1-22″) Results: 1232553600
Description: Return January 22, 2009 0:0 0 seconds timestamp
Second, the PHP timestamp function obtains the English text date time example as follows:
Easy to compare, use date to convert time stamp to system time with specified timestamp
(1) Print the timestamp for tomorrow at this time Strtotime ("+1 Day")
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("+1 Day") Results: 2009-01-23 09:40:25
(2) Print the timestamp at this time yesterday Strtotime ("-1 day")
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("1 day") Results: 2009-01-21 09:40:25
(3) Print timestamp strtotime ("+1 Week") at this time next week
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("+1 Week") Results: 2009-01-29 09:40:25
(4) Print timestamp strtotime ("1 week") at this time last week
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("1 Week") Results: 2009-01-15 09:40:25
(5) Print the time stamp specified next week strtotime ("next Thursday")
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("next Thursday") Results: 2009-01-29 00:00:00
(6) Print the timestamp strtotime ("last Thursday") specified on the previous day of the week
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Specified time: echo date ("Y-m-d h:i:s", Strtotime ("last Thursday")) Results: 2009-01-15 00:00:00
The PHP timestamp Function example above shows that Strtotime can parse the datetime description of any English text into a Unix timestamp, and we get the specified timestamp by combining mktime () or date () format date time to achieve the required date time.
Example:
?
<?php
/***************************************************************************
*
* Copyright (c) 2011 Baidu.com, Inc. All Rights Reserved
* $Id$
*
**************************************************************************/
//时间戳转日期
$date_time_array
=
getdate
(1297845628);
//1311177600 1316865566
$hours
=
$date_time_array
[
"hours"
];
$minutes
=
$date_time_array
[
"minutes"
];
$seconds
=
$date_time_array
[
"seconds"
];
$month
=
$date_time_array
[
"mon"
];
$day
=
$date_time_array
[
"mday"
];
$year
=
$date_time_array
[
"year"
];
echo
"year:$year\nmonth:$month\nday:$day\nhour:$hours\nminutes:$minutes\nseconds:$seconds\n"
;
//正常日期转时间戳
echo
mktime
(0, 0, 0, 9, 18, 2011) .
"\n"
;
echo
mktime
(0, 0, 0, 9, 25, 2011) .
"\n"
;
/*
time();
是获得当前时间,但获得的是一整型
*/
//可以对此进行格式化
echo
"time()显示年月日时分秒:"
.
date
(
"Y-m-d H:i:s"
, time()) .
"\n"
;
//这样连时,分秒一起显示
echo
"time()只显示年月日:"
.
date
(
"Y-m-d "
, time()) .
"\n"
;
//只年示年月日
echo
"时间戳格式化:"
.
date
(
"Y-m-d H:i:s"
, 1297845628) .
"\n"
;
//直接使用时间戳
/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */
?>
PHP Date conversion display and timestamp