每天的0点php,使用strtotime,这个月的第一天凌晨0点在PHP?(Using just strtotime, 0 am first day of this month in PHP?)...
使用strtotime,這個月的第一天凌晨0點(diǎn)在PHP?(Using just strtotime, 0 am first day of this month in PHP?)
echo mydate(strtotime('1 am first day of this month'));
以上工作結(jié)果2017-10-01 01:00:00 ,但我很難在凌晨0點(diǎn)做到。 24am, 24pm, 0pm, first second工作。
echo mydate(strtotime('1 am first day of this month'));
Above works with result 2017-10-01 01:00:00, but I have difficulty to do it for 0 am. Neither 24am, 24pm, 0pm, first second works.
原文:https://stackoverflow.com/questions/46974127
更新時間:2019-12-08 15:31
最滿意答案
使用midnight :
echo mydate(strtotime('midnight first day of this month'));
Use midnight:
echo mydate(strtotime('midnight first day of this month'));
2017-10-27
相關(guān)問答
你應(yīng)該使用mktime()函數(shù): <?php
echo date('Y-m-d', mktime(0,0,0,date('n')-1,1,date('Y'))); //2012-03-01
?>
請參閱實際操作 You should use the mktime() function: <?php
echo date('Y-m-d', mktime(0,0,0,date('n')-1,1,date('Y'))); //2012-03-01
?>
See In Action
嘗試這個: $dates = array("10 October 13:23", "12 November 08:12", "10 October 13:23");
foreach($dates as $d){
$exploded = explode(" ", $d);
$newDate = array_slice($exploded, 0,2,true)+array(2=>"2012")+array(3 => $exploded[2]);
...
使用midnight : echo mydate(strtotime('midnight first day of this month'));
演示 Use midnight: echo mydate(strtotime('midnight first day of this month'));
Demo
每月使用j ,而不是n是數(shù)字月份: php $date = date('l, F j, Y', strtotime($this->input->post('date')));
在行動中看到它 Use j for day of the month, not n which is the numeric month: php $date = date('l, F j, Y', strtotime($this->input->post('date')));
See it in action
這是不同版本的PHP的問題。 在php 5.2.7中有一個BC,來自文檔 : 在5.2.7之前的PHP 5中,請求在該工作日是該月的第一天的一個月中給定工作日的給定事件將錯誤地將一周添加到返回的時間戳。 這已在5.2.7及更高版本中得到糾正。 演示 服務(wù)器A的PHP> 5.2.7,服務(wù)器B的PHP <5.2.7。 This is a problem with different version of php. There is a BC in php 5.2.7, from the documen
...
這部分無關(guān) - 問題被編輯 由于時區(qū)差異。 $ start是在'Rainy River時區(qū)'計算的,而$ middle和$ end是UTC時間。 “雨河時區(qū)與UTC的時差為-06:00小時 (正好是第一次與第二次和第三次結(jié)果之差)。 更新1 - 解決方案 看來問題出現(xiàn)在時間周圍的某個地方。 由于某種原因,它會產(chǎn)生一天的偏差(需要進(jìn)一步解釋)。 一個簡單的解決方案是從該日期減去一秒鐘,它會產(chǎn)生正確的結(jié)果。 $timezone = new DateTimeZone('UTC');
$start = n
...
那么,關(guān)鍵字“的”是解決方案, strtotime(“2016-01”的第一個星期五)輸出1.1.2016 Well, the keyword "of" is the solution, strtotime("first friday of 2016-01") outputs 1.1.2016
您發(fā)布的代碼以您描述的方式失敗; 似乎PHP手冊頁中的描述(正如SilentGhost所提到的,只是用戶注釋)是未經(jīng)過驗證的代碼。 如果您需要某個特定月份的最后一天,請嘗試以下操作: date('Y-m-d', strtotime("2009-12 next month - 1 hour"));
The code you posted fails in the manner you described; it seems that the description in the PHP manua
...
您在嘗試檢索該月的第一天時缺少關(guān)鍵字 echo date('Y-m-d', strtotime('First Monday of '.date('F o', strtotime("-4 months")));
我找到了這個bug報告的信息 我目前的版本是PHP 5.4.4,以防它仍然不適合你 You are missing the keyword of when trying to retrieve the first day of the month echo date('Y-m-d', st
...
總結(jié)
以上是生活随笔為你收集整理的每天的0点php,使用strtotime,这个月的第一天凌晨0点在PHP?(Using just strtotime, 0 am first day of this month in PHP?)...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 紫菜苔的功效与作用、禁忌和食用方法
- 下一篇: 干桑椹的功效与作用、禁忌和食用方法