月份名称到月份号 - 03为2月? [英] Month name to month number - 03 for Feb?
问题描述
我正在尝试将字符串月份名称转换为月份号,
但是为什么在结果中得到 '03' strong>'Feb' in
strtolower(date('m',strtotime('Feb')) );
我用其他月份的名字测试,似乎很好,
strtolower(date('m',strtotime('Jan'))); // 01
strtolower(date('m',strtotime('Mar'))); // 03
做错了什么?
从 php.net手册:
该函数希望给出一个包含英文日期
格式的字符串,并尝试解析该格式成为一个Unix时间戳(相对于现在给出的
时间戳的
从1970年1月1日00:00:00 UTC开始的秒数),或当前时间(如果现在不提供) / em>
这将导致今天(1月30日)和Feb=> 2月30日的混合,不是有效的日期,所以PHP返回3月份的月份号。
尝试像
strtotime('01 Feb')
应该可以解决问题。 p>
I am trying to convert string month name to month number,
but why do I get '03' in the result for 'Feb' in,
strtolower(date('m', strtotime('Feb')));
I tested with other month names and they seem to be fine,
strtolower(date('m', strtotime('Jan'))); // 01
strtolower(date('m', strtotime('Mar'))); // 03
What have done wrong?
From the php.net manual:
The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.
This results in a mixture of todays date (January 30th) and "Feb" => February 30th - but this is not a valid date, so PHP returns the month number for March.
Trying something like
strtotime('01 Feb')
should solve the problem.
这篇关于月份名称到月份号 - 03为2月?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!