[英]PHP - Getting next thursday's date
碼
$order_dispatch_date = DateTime::createFromFormat('Ymd', $inc['order_dispatch_date']);
$order_dispatch_date = $order_dispatch_date->format('Ymd');
$order_collection = date('Ymd', strtotime('next thursday', $order_dispatch_date));
$order_collection = new DateTime($order_collection);
echo '['.$order_collection->format('d/m/Y') . ' - ' . $order_dispatch_date . ' - ' . gettype($order_dispatch_date) . ' ] ';
如果輸入是,則得到以下輸出: 20171128
[29/08/1970 - 20171128 - string ]
我的問題是,為什么第一個輸出顯示1970年8月29日而不是2017年11月20日?
停止在對象,字符串和時間戳之間來回更改太多,尤其是當您重新使用相同的變量時。 不必要地很難遵循。
如果您有Ymd
格式的字符串,並且希望在星期四返回一個等效的字符串,請使用以下命令:
$inc['order_dispatch_date'] = '20171128';
$order_dispatch_date = DateTime::createFromFormat('Ymd', $inc['order_dispatch_date'])->modify('next thursday');
echo $order_dispatch_date->format('Ymd');
// 20171130
基本上:
$order_collection = date('Ymd', strtotime('next thursday', strtotime($order_dispatch_date)));
那應該工作:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.