所以我以##的形式有一个PHP变量w / a(可能是当前的,可能不是)月份。如果月份比10月少,我想领先0。有一个好的和简单的方法来做到这一点?
答案 0 :(得分:7)
您可以使用内置日期功能来执行此操作,应该类似于
<?php
date('n/d/Y',strtotime($dateVariable));
?>
您可以使用n而不是m来显示没有前导零的月份。
有关日期格式的详细信息,请参阅http://php.net/manual/en/function.date.php。
答案 1 :(得分:6)
将其转换为整数:
<?php
$month = '01';
echo (int) $month; // prints 1
?>
答案 2 :(得分:1)
<?php
$month = '05'; // May
$month *= 1;
echo $month;
?>
输出
5
答案 3 :(得分:1)
答案 4 :(得分:0)
你可以这样做:
<?php
$month = intval(Date('m'));
echo $month; // prints int value
?>