[英]How to create a PHP if function to determine cut-off delivery time?
I try to create a small if statement on a webpage to check if a parcel gets delivered today or tomorrow. 我尝试在网页上创建一个小的if语句,以检查包裹是今天还是明天交付。 However it is not working.
但是,它不起作用。
This is what I tried: 这是我尝试的:
<?php if(date('G') < 11) : ?>
<div class="single-product-delivery">
<i class="fa fa-check" style="font-size: 20px; color: #0bbbef;"></i>
<span class="product-single-span">Order before 11:00, delivery tonight!</span>
</div>
<?php else : ?>
<div class="single-product-delivery">
<i class="fa fa-check" style="font-size: 20px; color: #0bbbef;"></i>
<span class="product-single-span">Order before 23:59, next day delivery!</span>
</div>
<?php endif; ?>
This should work right? 这应该工作对吗? However I am seeing "Order before 23:59, next day delivery!"
但是,我看到的是“第二天交货23:59之前订购!” right now and the time is before 11.
现在,时间是11点之前。
Can someone help? 有人可以帮忙吗?
Try working temporarily with your time zone. 尝试暂时使用您的时区。 Using date_default_timezone_set is not a good idea.
使用date_default_timezone_set不是一个好主意。 The effects are not manageable.
影响是无法控制的。
$localHour = date_create('now', new DateTimeZone('Europe/Berlin'))->format('G');
if($localHour < 11) ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.