PHP获取当前日期的日期

Dun*_*key 3 php

各位大家好,我想获得当前的约会对象.

这是我试过的:

   <?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";
   }

    ?>
Run Code Online (Sandbox Code Playgroud)

但结果是错误的,它应该显示12月是月份:0

有任何想法吗?谢谢.

Ani*_*ena 10

这段代码对你有用

<?php 
$month = date('m');

if($month == 12){
   echo "<br />December is the month :)";
} else {
   echo "<br /> The month is probably not December";
}
?>
Run Code Online (Sandbox Code Playgroud)


Azi*_*ima 9

为什么不简单

echo date('F, Y');
Run Code Online (Sandbox Code Playgroud)

? 打印时间为 2017 年 11 月。


Lia*_*and 9

我建议您使用函数idate(),它返回一个整数而不是格式化字符串。

$month = idate("m");
Run Code Online (Sandbox Code Playgroud)


Kin*_*ell 5

这是一个更好的方法

echo date("F", strtotime('m'));
Run Code Online (Sandbox Code Playgroud)