【问题标题】:How do you get the name of the day that is the first day of the certain Month/Year in php?你如何在php中获得某个月/年的第一天的名称?
【发布时间】:2012-03-30 13:53:33
【问题描述】:

我需要创建一个以月份和年份为参数的函数,并返回当月 1 日的日期名称。

例如今天是 2012 年 3 月的第 30 天,我如何知道哪一天是第 1 天?我只知道2012年3月。 抱歉重复了,我只想说清楚。

【问题讨论】:

    标签: php function date


    【解决方案1】:

    使用strtotimedate 函数的组合:

    $f_dt = strtotime("$month/01/$year");
    $day = date('D', $f_dt);
    

    【讨论】:

      【解决方案2】:

      Ack,完全误读了...好吧,应该是date('D',strtotime($year.'-'.$month.'-01'))

      我假设您的日期名称是指星期一、星期二等。如果您想写出日期而不是星期一、星期二等,请将那里的“D”参数更改为“l”(小写 L)。

      【讨论】:

      • 你第一次做对了。 D 代表全名,l 代表前三个字母
      • 也非常感谢! (在你编辑之前,我的脸很用力..)
      猜你喜欢
      • 1970-01-01
      • 2011-03-20
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多