<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 語法 ~~~ strtotime(time,now); ~~~ | 參數 | 描述 | | --- | --- | | *time* | 必需。規定日期/時間字符串。 | | *now* | 可選。規定用來計算返回值的時間戳。如果省略該參數,則使用當前時間。 | 最近做數據可視化 用的圖表 echarts.js 然后傳參橫坐標日期時用到了strtotime這個函數,結果發現有坑,昨天是2019-05-30都是正常的,發版后今天31號就全錯了 原代碼 ``` // 以指定格式$format,顯示最近$monthLong個月的數據,用來作為圖標橫坐標 function createMonthLine($monthLong, $format= "ym"){ $monthLine = []; for ($i=1; $i<= $monthLong; $i++){ $monthLine[] = date($format, strtotime("-".($monthLong-$i)." month")); } return $monthLine; } ``` 新代碼 ``` function createMonthLine($monthLong, $format= "ym"){ $monthLine = []; for ($i=1; $i<= $monthLong; $i++){ $monthLine[] = date($format, strtotime("first day of -".($monthLong-$i)." month")); } return $monthLine; } ``` 其中的原理,見鳥哥博客分析: http://www.laruence.com/2018/07/31/3207.html 大概原因是 如下規則 ## 以當前傳值日期 按照要求處理年月日 如果年月日被處理后超過了合理值,會自動進一位;當月日滿進月位, 當年月滿進年位 試下幾個代碼就知道問題了 ``` var_dump(date("Y-m-d", strtotime("2019-02-31"))); # 2019-03-03 # 2019年的2月只有28天 日滿進月 日取余; 變為2019-03-03 符合 var_dump(date("Y-m-d", strtotime("2019-12-32"))); # 1970-01-01 # 不符合期望 以為會是 12月沒有32 進1月 然后月滿進年 最后為 2020-01-01 var_dump(date("Y-m-d", strtotime("2019-13-01"))); # 1970-01-01 # 不符合期望 以為會是 1年沒有12個月 進1年 最后為 2020-01-01 var_dump(date("Y-m-d", strtotime("-1 month", strtotime("2019-08-31")))); # 2019-07-31 正常日期 var_dump(date("Y-m-d", strtotime("+1 month", strtotime("2019-08-31")))); # 2019-10-01 9月沒有31號,日滿進月 var_dump(date("Y-m-d", strtotime("-1 month", strtotime("2019-03-27")))); # 2019-02-27 也并不是評論里所說減去上個月的天數 var_dump(date("Y-m-d", strtotime("+1 month", strtotime("2019-12-31")))); # 2020-01-31 月滿進年 var_dump(date("Y-m-d", strtotime("-1 month", strtotime("2020-01-31")))); # 2019-12-31 月減退年 var_dump(date("Y-m-d", strtotime("2020-01-31 -1 month"))); # 2019-12-31 月減退年 ``` 結論如下: 1.進位規則在顯示指定被處理的日期時, 日進位退位正常,月退位正常,進位異常,會導致年變成1970 2.進位規則在默認指定被處理日期為當前時, 日月年進位退位均正常 ## 回看這里時,突然發現實際的需求其實是獲得上月或者下月的同期。比如 ### 昨天 ``` date('Y-m-d', strtotime('yesterday')); date('Y-m-d', strtotime('last day')); ``` ### 明天 ``` date('Y-m-d', strtotime('tomorrow')); date('Y-m-d', strtotime('next day')); ``` ### 月初 ``` date('Y-m-01'); date('Y-m-d', strtotime('first day of this month')); ``` ### 月末 ``` date('Y-m-01'); date('Y-m-d', strtotime('last day of this month')); ``` ### 形容性日期 有 of 默認參照都是今天今月今天 \*年\*月的X天,其中*可以為 last this next 分別代表{上|本|下}{月|年},X可以為first last 表示{第一|最后}天 ``` date('Y-m-d', strtotime('X day of * month * year')); ``` ### 非形容性日期 無 of 默認參照都是今天今月今天 \*年\*月的\*天,其中*可以為 last this next 分別代表{上|本|下}{月|年} ``` date('Y-m-d', strtotime('X day * month * year')); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看