PHP将短月份名称转换为月份号码

I-M*_*-JM 0 php

可能重复:
将月份从名称转换为数字

我有一个简单(但有趣)的查询.

我正在获得月份名称,简而言之,就像Jan,Feb等.现在我需要将其转换为月份数(即一个月的数字表示),前导零

示例:"Jan"到"01","Dec"到"12"等

任何人都知道,如何实现这一点,而不使用数组

谢谢

dec*_*eze 16

$month = 'Feb';
echo date('m', strtotime($month));
Run Code Online (Sandbox Code Playgroud)

strtotime将"Feb"转换为2011年2月6日15:15:00(写作时)的时间戳,从给定的字符串中取出它可以从当前时间填充空白.date('m')然后格式化此时间戳,仅输出月份数.

因为这实际上可能会引起问题,例如31日,你应该填写这些空白以确定:

echo date('m', strtotime("$month 1 2011"));
Run Code Online (Sandbox Code Playgroud)