PHP: strototime 上周日晚上 8 点
PHP: strototime last Sunday at 8 PM
我需要获取最后一个星期天晚上8点的Unix时间戳,所以我尝试了:
strtotime("last sunday 8 pm");
效果很好,但如果是 22-11-2015
晚上 9 点,输出是 15-11-2015 8 PM
而不是一小时前。除了星期天的最后四个小时外,上述方法效果很好。我怎样才能得到22-11-2015 8 PM
?
完成此任务的正确但更长的方法
if((date('D',time()) == 'Sun') && (time() > strtotime('today 8 pm'))){ //if today is sunday and after 8pm, give todays date.
$unix = strtotime('today 8 pm');
}
else{ //not sunday today, return last sunday.
$unix = strtotime('last sunday');
}
Hacky/Original代码:
您可以从明天开始检查 "last sunday 8 pm"。
strtotime('last sunday 8 pm', strtotime('tomorrow'));
我需要获取最后一个星期天晚上8点的Unix时间戳,所以我尝试了:
strtotime("last sunday 8 pm");
效果很好,但如果是 22-11-2015
晚上 9 点,输出是 15-11-2015 8 PM
而不是一小时前。除了星期天的最后四个小时外,上述方法效果很好。我怎样才能得到22-11-2015 8 PM
?
完成此任务的正确但更长的方法
if((date('D',time()) == 'Sun') && (time() > strtotime('today 8 pm'))){ //if today is sunday and after 8pm, give todays date.
$unix = strtotime('today 8 pm');
}
else{ //not sunday today, return last sunday.
$unix = strtotime('last sunday');
}
Hacky/Original代码: 您可以从明天开始检查 "last sunday 8 pm"。
strtotime('last sunday 8 pm', strtotime('tomorrow'));