【问题标题】:Get a month's first day in a string(Monday,Tuesday) in php在php中的字符串(星期一,星期二)中获取一个月的第一天
【发布时间】:2016-11-06 21:49:13
【问题描述】:

我一直试图在一个月的字符串中获得第一天。 我有两个变量:

$year = 2016;
$month = "November";

我想得到 2016 年 11 月的第一天(即星期二)。 我试过了

$string = "$year-$month-01";
echo date("l",strtotime($string));

还有

$string = "$year-$month-01";
echo date("l",$string);

请帮帮我!

【问题讨论】:

    标签: php date calendar


    【解决方案1】:

    您忘记了相对于您所在位置的 UTC 时区偏移量。代码的最小修复是使用gmdate

    <?php
    
    $year = 2016;
    $month = "November";
    
    $string = "$year-$month-01";
    echo gmdate("l",strtotime($string));
    

    星期二

    【讨论】:

      猜你喜欢
      • 2019-10-19
      • 2021-09-06
      • 1970-01-01
      • 2011-12-05
      • 2014-07-21
      • 2021-05-25
      • 1970-01-01
      • 2019-03-09
      • 1970-01-01
      相关资源
      最近更新 更多