使用碳获取上个月的第一天时间戳



我想在 laravel 中使用 Carbon 获取上个月第一天和上个月最后一天的时间戳(以毫秒为单位(。

我尝试用carbon::p arse来做到这一点,这是可以实现的。但我想实例化碳类只是为了达到同样的目的。

这是适用于 Carbon::p arse 的代码

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

您可以尝试以下代码

$previous_month_start = Carbon::now()->subMonth()->startOfMonth()->format('x');
$previous_month_end = Carbon::now()->subMonth()->endOfMonth()->format('x');

最新更新