获取Carbon上个月的第一天时间戳

问题描述 投票:0回答:1

我希望在上个月的第一天和上个月的最后一天使用Carbon in laravel获得时间戳(以毫秒为单位)。

我试图用carbon :: parse来实现它,这是实现的。但我想实例化Carbon类只是为了达到同样的目的。

这是与Carbon :: parse一起使用的代码

Carbon::parse('first day of last month',$timezone)->timestamp

但我想用下面的东西来实现同样的目标。

$start = new Carbon('first day of last month');

$end = new Carbon('last day of last month');

输出应该是以毫秒为单位的时间戳。像1555704794000

laravel-5 php-carbon timestamp-with-timezone
1个回答
0
投票

您可以尝试以下代码

$previous_month_start = Carbon::now()->subMonth()->startOfMonth()->format('x');
$previous_month_end = Carbon::now()->subMonth()->endOfMonth()->format('x');
© www.soinside.com 2019 - 2024. All rights reserved.