dqz84361326 2015-04-06 22:20 采纳率: 0%
浏览 60

缩短月份的时间戳php

I need a list which iterates through the months and always shows the last days like this

2015-04-30
2015-03-31
2015-02-28
...

My idea was to do this with the strtotime method, where '1430344800' is the timestep according to 2015-04-30

$time_temp = 1430344800;
echo date('Y-m-t',$time_temp)."<br>";

$time_temp  =   strtotime("-1 month",$time_temp);
echo date('Y-m-t',$time_temp)."<br>";

$time_temp  =   strtotime("-1 month",$time_temp);
echo date('Y-m-t',$time_temp)."<br>";

but I just get

2015-04-30
2015-03-31
2015-03-31

replacing 'Y-m-t' by 'Y-m-d' gives

2015-04-30
2015-03-30
2015-03-02

Why is it not reducing the month properly and how can I accomplish it?

  • 写回答

1条回答 默认 最新

  • donglaohua1671 2015-04-06 22:25
    关注
    $lastDayOfMonth = time(); // depending on what you're trying to do, this could change. 
    // For example, it could be = strtotime("+1 month");
    for( $i = 0; $i < $numberOfMonthsToShow; $i++ ){
        $lastDayOfMonth = strtotime("last day of previous month", $lastDayOfMonth);
        echo date('Y-n-j', $lastDayOfMonth).'<br />';
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分