我正在寫一個小的時間計算。給定時間應(yīng)該總是增加3小時。但是,如果我在php中執(zhí)行"+3 h"該方法strtotime(),它將輸出另一個值。所以我想知道為什么"+3 hours"會起作用。有人可以解釋一下為什么嗎?我的php版本是: 7.0.33-0ubuntu0.16.04.4$date = "2019-05-04 15:00"; //format is Y-m-d H:i$out = date("Y-m-d H:i", strtotime("+3 h", strtotime($date)));echo $out; //out = 2019-05-04 14:00$date = "2019-05-04 15:00"; //format is Y-m-d H:i$out = date("Y-m-d H:i", strtotime("+3 hours", strtotime($date)));echo $out; //out = 2019-05-04 18:00這是我的測試示例代碼。并且$date每15分鐘有一個不同的值。PS:這是我關(guān)于stackoverflow的第一個問題-Hello World:D
1 回答

子衿沉夜
TA貢獻1828條經(jīng)驗 獲得超3個贊
strtotime-將任何英文文本日期時間描述解析為Unix時間戳
您需要使用hour
OR hours
??梢允褂?code>day或的日子相似days
。
$date = "2019-05-04 15:00"; //format is Y-m-d H:i
$out = date("Y-m-d H:i", strtotime("+3 h", strtotime($date)));
echo $out; //out = 2019-05-04 12:00
輸出顯示為2019-05-04 12:00not 2019-05-04 14:00。
似乎您輸入了錯誤的格式;ike +3 h,它只是從原始時間中減去
- 1 回答
- 0 關(guān)注
- 161 瀏覽
添加回答
舉報
0/150
提交
取消