大家好,我想获取日期的当前月份。
这是我尝试过的:
<?php
$transdate = date('m-d-Y', time());
echo $transdate;
$month = date('m', strtotime($transdate));
if ($month == "12") {
echo "<br />December is the month :)";
} else {
echo "<br /> The month is probably not December";
}
?>
但结果是错误的,应该显示十二月是月份:0有任何想法吗?谢谢。
最佳答案
您需要使用 PHP 的默认 date() 函数来获取当前月份。然后,您可以通过以下代码中提到的 if 条件轻松检查它:
<?php
$month = date('m');
if($month == 12){
echo "<br />December is the month :)";
} else {
echo "<br /> The month is probably not December";
}
?>
关于PHP 获取日期的当前月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20659389/