我想串月份名稱轉換爲月數,月份名稱到月份編號 - 03月份是2月份?
,但爲什麼會在結果「03」爲「二月」中,
strtolower(date('m', strtotime('Feb')));
我與其他測試他們似乎很好,
strtolower(date('m', strtotime('Jan'))); // 01
strtolower(date('m', strtotime('Mar'))); // 03
什麼做錯了?
我想串月份名稱轉換爲月數,月份名稱到月份編號 - 03月份是2月份?
,但爲什麼會在結果「03」爲「二月」中,
strtolower(date('m', strtotime('Feb')));
我與其他測試他們似乎很好,
strtolower(date('m', strtotime('Jan'))); // 01
strtolower(date('m', strtotime('Mar'))); // 03
什麼做錯了?
函數需要接受一個包含英語日期 格式的字符串,並會嘗試解析格式爲Unix時間戳(因爲 秒數1970年00年1月1 :00:00 UTC),相對於現在給出的 時間戳,或者當前時間(如果現在不提供)。
這導致今天的日期(1月30日)和「2月」=> 2月30日的混合 - 但這不是有效的日期,所以PHP返回3月的月份數。
試圖像
strtotime('01 Feb')
應該解決的問題。
明白了。感謝schnaader的答案。 – laukok 2012-01-30 12:46:10
因爲今天是1月第30個。你沒有提供一天數字,所以php假設今天是2月30日。然後它意識到是無效的,所以它繼續到3月2日,困惑的事情。
感謝羅布的答案。 – laukok 2012-01-30 12:46:31
3月1日,實際上,自2月29日以來*今年*確實存在。 – lonesomeday 2012-01-30 14:21:23
因爲今天是第30。嘗試爲每個字符串添加'1st' – 2012-01-30 12:35:18
確實:嘗試'strtolower(date('m',strtotime('Feb')))' – lonesomeday 2012-01-30 12:36:13
您還沒有指定日期和年份。在任何情況下,你遇到一個具體的PHP函數的問題,請首先閱讀有關它的手冊條目:http://php.net/strtotime – hakre 2012-01-30 12:41:53