将月份从名称转换为数字 [英] convert month from name to number
本文介绍了将月份从名称转换为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种简单的方法来更改$month = "July";
,以使$nmonth = 7
(也可以使用07
).
我可以做一个case语句,但是肯定已经有一个要转换的函数了吗?
我希望我能接受多个答案,因为你们两个人基本上给了我我所需的一切力量.
Is there an easy way to change $month = "July";
so that $nmonth = 7
(07
would be fine too).
I could do a case statement, but surely there is already a function to convert?
I wish I could accept multiple answers, cause two of you basically gave me what I needed by your powers combined.
$nmonth = date('m',strtotime($month));
这将给出$month
的数值.
谢谢!
That will give the numerical value for $month
.
Thanks!
推荐答案
是
$date = 'July 25 2010';
echo date('d/m/Y', strtotime($date));
m
将月份格式化为在那里的数字表示形式.
The m
formats the month to its numerical representation there.
这篇关于将月份从名称转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文