常用日期时间范围
DateTimeHelper
<?php
namespace App\Test;
class DateTimeHelper
{
public static function todayBegin($isTimeStamp = false)
{
$timeStamp = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
public static function todayEnd($isTimeStamp = false)
{
$timeStamp = mktime(23, 59, 59, date('m'), date('d'), date('Y'));
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
public static function yesterdayBegin($isTimeStamp = false)
{
$timeStamp = self::todayBegin(true) - 1 * 24 * 3600;
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
public static function yesterdayEnd($isTimeStamp = false)
{
$timeStamp = self::todayEnd(true) - 1 * 24 * 3600;
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
public static function weekBegin($isTimeStamp = false)
{
$timeStamp = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y'));
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
public static function weekEnd($isTimeStamp = false)
{
$timeStamp = mktime(23, 59, 59, date('m'), date('d') - date('w') + 7, date('Y'));
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
public static function lastWeekBegin($isTimeStamp = false)
{
$timeStamp = self::weekBegin(true) - 7 * 24 * 3600;
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
public static function lastWeekEnd($isTimeStamp = false)
{
$timeStamp = self::weekEnd(true) - 7 * 24 * 3600;
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
public static function monthBegin($isTimeStamp = false)
{
$timeStamp = mktime(0, 0, 0, date('m'), 1, date('Y'));
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
public static function monthEnd($isTimeStamp = false)
{
$timeStamp = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
public static function yearBegin($isTimeStamp = false)
{
$timeStamp = mktime(0, 0, 0, 1, 1, date('Y'));
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
public static function yearEnd($isTimeStamp = false)
{
$timeStamp = mktime(23, 59, 59, 12, 31, date('Y'));
return $isTimeStamp ? $timeStamp : date('Y-m-d H:i:s', $timeStamp);
}
}