从一天开始的PhP时间戳


PhP timestamp from a day

我有点怀疑。

我怎么知道时间戳从X天,大约小时00:00:00到23:59:59?

我猜time()只是给了你当前的时间戳,我需要从一天开始到最后一天的时间戳,这样我就可以在MySQL中检查我的DB在这些时间之间的一刻。

strtotime将日期从字符串转换为时间戳。

$start_date = "2012-01-10";
$end_date = "2012-04-14";
$start = strtotime($start_date . " 00:00:00");
$end = strtotime($end_date . " 23:59:59");
$today = new DateTime();
$morning = $today->format('Y-m-d 00:00:00');
$evening = $today->format('Y-m-d 23:59:59');

您可以使用mktime()。

http://php.net/manual/en/function.mktime.php

// Set the default timezone to use. Available as of PHP 5.1
date_default_timezone_set('UTC');
// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));
// Prints something like: 2006-04-05T01:02:03+00:00
echo date('c', mktime(1, 2, 3, 4, 5, 2006));

看一下strtotime函数,例如

$date1 = 'today 00:00:00';
$date2 = 'today 23:59:59';
$unixTime1 = strtotime($date1);
$unixTime2 = strtotime($date2);