`Carbon->timestamp` 但没有秒
`Carbon->timestamp` but without seconds
有什么 Carbon
方法 可以获取 Carbon
对象的时间戳,但没有秒?
我需要比较两个 Carbon
对象,但我不想考虑秒...
if ($carbon1->timestamp > $carbon2->timestamp) {
// Do something...
}
我不想使用像
这样的解决方案
$timestampWithoutSeconds = substr($carbon1->timestamp, 0, 5);
假设您的时间戳以毫秒为单位,您可以从中减去秒数。
假设您的时间戳是 1564562500699,即 2019 年 7 月 31 日星期三 10:41:40 GMT+0200(中欧夏令时)
$timestamp = 1564562500699;
$milliseconds = $timestamp % (60*1000); // 40699
$timestampWithoutSeconds = $timestamp - $milliseconds;
// Your condition
如果你想要一个像 subSeconds used with second getter 这样的 Carbon 解决方案:
$carbon1->subSeconds($carbon1->second);
您可以放置 Carbon 对象:
if ($carbon1->floorMinute() > $carbon2->floorMinute()) {
// Do something...
}
或 ->roundMinute()
取决于您想要更短或最接近的分钟。
有什么 Carbon
方法 可以获取 Carbon
对象的时间戳,但没有秒?
我需要比较两个 Carbon
对象,但我不想考虑秒...
if ($carbon1->timestamp > $carbon2->timestamp) {
// Do something...
}
我不想使用像
这样的解决方案$timestampWithoutSeconds = substr($carbon1->timestamp, 0, 5);
假设您的时间戳以毫秒为单位,您可以从中减去秒数。
假设您的时间戳是 1564562500699,即 2019 年 7 月 31 日星期三 10:41:40 GMT+0200(中欧夏令时)
$timestamp = 1564562500699;
$milliseconds = $timestamp % (60*1000); // 40699
$timestampWithoutSeconds = $timestamp - $milliseconds;
// Your condition
如果你想要一个像 subSeconds used with second getter 这样的 Carbon 解决方案:
$carbon1->subSeconds($carbon1->second);
您可以放置 Carbon 对象:
if ($carbon1->floorMinute() > $carbon2->floorMinute()) {
// Do something...
}
或 ->roundMinute()
取决于您想要更短或最接近的分钟。