Php 如何检查此时间戳是今天、明天还是后天?
我想知道如何检查时间戳是今天、明天还是后天 我有,例如:Php 如何检查此时间戳是今天、明天还是后天?,php,date,Php,Date,我想知道如何检查时间戳是今天、明天还是后天 我有,例如: $timestamp = "1313000474"; 如何检查此时间戳是今天、明天还是后天 e、 g 如何做到这一点 编辑:更正的unix时间戳 提前谢谢。保持代码整洁 <?php $time = "20060713174545"; $date = date('Y-m-d', strtotime($time)); $now = date('Y-m-d'); $tomorrow = date('Y-m-d', time() + s
$timestamp = "1313000474";
如何检查此时间戳是今天、明天还是后天
e、 g
如何做到这一点
编辑:更正的unix时间戳
提前谢谢。
保持代码整洁
<?php
$time = "20060713174545";
$date = date('Y-m-d', strtotime($time));
$now = date('Y-m-d');
$tomorrow = date('Y-m-d', time() + strtotime('tomorrow'));
$day_after_tomorrow = date('Y-m-d', time() + strtotime('tomorrow + 1 day'));
if ($date == $now){
echo "It's today";
}
elseif($date == $tomorrow){
echo "It's tomorrow";
}
elseif($date == $day_after_tomorrow){
echo "It's day after tomorrow";
}
else{
echo "None of previous if statements passed";
}
$timestamp = "1313000474";
// Description demonstrate proposes only...
$compare_dates = array(
'today' => 'today!!',
'tomorrow' => 'Tomorrow!!!',
'tomorrow +1 day' => 'day after tomorrow? YEAH',
);
foreach($compare_dates => $compare_date => $compare_date_desc){
if(strtotime($compare_date) > $timestamp && $timestamp < strtotime($compare_date.' +1 day') ){
echo $compare_date_desc;
break;
}
}
$timestamp=“1313000474”;
//说明仅建议。。。
$compare\u dates=数组(
“今天”=>“今天!!”,
“明天”=>“明天!!!”,
“明天+1天”=>“后天?是的”,
);
foreach($compare\u dates=>$compare\u date=>$compare\u date\u desc){
if(strotime($compare_date)>$timestamp&&$timestamp
编辑:如果时间戳已经没有小时、分钟和秒,你就不必担心了。。。或者创建不同的输出日期,替换echo$compare\u date\u desc代码>按回显日期($compare\u date\u desc,$timestamp)代码>
这不是unix时间戳。那是什么?2006/07/13是日期部分吗?什么是174545?军事时间?在我看来像是
yyyyMMddHHmmss
。i、 e.174545=下午5:45:45。对不起,我现在已经更正了。在当前时间的基础上增加24小时不一定等于明天。在许多国家,一年中有一天有23个小时。你把它弄得更糟了。time()+strotime(“+2天”)将是2011-08-10的时间戳+2011-08-13的时间戳=41年。这到底是怎么回事?看起来像是复制的?真的吗,伙计?我们做的一件事都不一样,我也没有理由复制您的代码,这在逻辑上是不正确的,并且不会产生所需的输出。
$timestamp = "1313000474";
$date = date('Y-m-d', $timestamp);
$today = date('Y-m-d');
$tomorrow = date('Y-m-d', strtotime('tomorrow'));
$day_after_tomorrow = date('Y-m-d', strtotime('tomorrow + 1 day'));
if ($date == $today) {
echo "today";
} else if ($date == $tomorrow) {
echo "tomorrow";
} else if ($date == $day_after_tomorrow) {
echo "dayaftertomorrow";
}
$timestamp = "1313000474";
// Description demonstrate proposes only...
$compare_dates = array(
'today' => 'today!!',
'tomorrow' => 'Tomorrow!!!',
'tomorrow +1 day' => 'day after tomorrow? YEAH',
);
foreach($compare_dates => $compare_date => $compare_date_desc){
if(strtotime($compare_date) > $timestamp && $timestamp < strtotime($compare_date.' +1 day') ){
echo $compare_date_desc;
break;
}
}
<?php
function getTheDay($date)
{
$curr_date=strtotime(date("Y-m-d H:i:s"));
$the_date=strtotime($date);
$diff=floor(($curr_date-$the_date)/(60*60*24));
switch($diff)
{
case 0:
return "Today";
break;
case 1:
return "Yesterday";
break;
default:
return $diff." Days ago";
}
}
?>