dongpengyu1363 2014-07-10 08:53
浏览 38
已采纳

基于一年的月份的第一个和最后一个日期的列表

I want to create a function which outputs a list of the first date of the month and last date of the month based on the year, which is given as an argument.

function first_and_last_dates_of_month($year){
//code
}

first_and_last_dates_of_month(2014);

I want to have the output somthing like this:

2014-01-01
2014-01-31
2014-02-01
2014-02-28
2014-03-01
2014-03-31
2014-04-01
2014-04-30
2014-05-01
2014-05-31
2014-06-01
2014-06-30
2014-07-01
2014-07-31
2014-08-01
2014-08-31
2014-09-01
2014-09-30
2014-10-01
2014-10-31
2014-11-01
2014-11-30
2014-12-01
2014-12-31
  • 写回答

2条回答 默认 最新

  • doufei4923 2014-07-10 09:20
    关注

    Hope it will help you:

    function first_and_last_dates_of_month($year=2014){
        for ($i=1; $i<=12; $i++) {
            $timestamp = strtotime(date("$i/01/y"));
            echo "<br/>";
            echo $first_second = date('Y-m-01', $timestamp);
            echo "<br/>";
            echo $last_second  = date('Y-m-t', $timestamp);
        }
    }
    
    first_and_last_dates_of_month(2014);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记