【问题标题】:PHP get weekday of setDate()PHP 获取 setDate() 的工作日
【发布时间】:2013-02-25 05:32:55
【问题描述】:

我正在尝试在 php.ini 中创建日历。我需要得到该月第一天的工作日(周日、周一等)。到目前为止我的代码是:

<?php
$current_month = date("n");
$current_year = date("Y");
$first_day_of_month = new DateTime();
$first_day_of_month -> setDate($current_year,$current_month,1);
?>

我不知道如何获取设定日期的工作日(每月的第一天)。有什么建议吗?

【问题讨论】:

    标签: php date weekday


    【解决方案1】:

    你可以使用这个类的format函数,并给出你想要的格式。

    以下是应该工作的日期格式列表:

    date format

    示例:

    $first_day_of_month->format('D');
    

    注意:查看类定义了解更多问题:

    DateTime

    【讨论】:

      【解决方案2】:

      试试,

       echo date("l", mktime(0,0,0,date("n"),1,date("Y")));
      

      在你的情况下,

      echo date("l", mktime(0,0,0,$current_month,1,$current_year));
      

      【讨论】:

        【解决方案3】:

        这是给你的扩展代码

        <?php
        $current_month = date("n");
        $current_year = date("Y");
        $first_day_of_month = new DateTime();
        $first_day_of_month -> setDate($current_year,$current_month,1);
        
        $timestamp = strtotime($first_day_of_month);
        
        $day = date('D', $timestamp);
        var_dump($day);
        
        ?>
        

        这会给你那一天。

        【讨论】:

          【解决方案4】:

          $timestamp = strtotime($current_year-$current_month-1); $day = date('D', $timestamp);

          回声 $day;

          我希望上面提到的代码对你有用。

          帕万

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2016-11-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-06-26
            • 2017-03-25
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多