【问题标题】:Carbon date from from now() to past 30 days碳日期从现在()到过去 30 天
【发布时间】:2018-08-25 00:28:54
【问题描述】:

嘿伙计们,过去 30 天我一直在尝试在 laravel 中获取一个数组。尝试使用 Carbon 来获取现在的日子,并希望将其倒数 30 天,知道我该如何完成吗?示例 19、18、17、16、15、14 等

【问题讨论】:

标签: arrays laravel


【解决方案1】:

这个问题之前在这里被问过link to question

我从另一个答案中复制了代码以供参考:

$period = CarbonPeriod::create('2018-06-14', '2018-06-20');

// Iterate over the period
foreach ($period as $date) {
    echo $date->format('Y-m-d');
}

// Convert the period to an array of dates
$dates = $period->toArray();

【讨论】:

    【解决方案2】:

    不确定你到底想要什么,但我相信这就是你要找的......

    $now = \Carbon\Carbon::now();
    
    $dates = [$now->format('M d, Y')];
    
    for($i = 1; $i < 30; $i++) {
      $dates[] = $now->subDays($i)->format('M d, Y');
    }
    
    print_r($dates);
    

    如果这能解决您的问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多