private $current_time; // 当前时间戳
private $current_day; // 当前天
private $current_mouth; // 当前月
private $current_year; // 当前年
private $current_mouth_last_day; // 当前月份每天的起始时间
public function __construct(StatisticsService $statisticsService)
{
$this->statisticsService = $statisticsService;
// 当前时间戳
$this->current_time = time();
// 当前天
$this->current_day = date('d', $this->current_time);
// 当前月份
$this->current_mouth = date('m', $this->current_time);
// 当前年
$this->current_year = date('Y', $this->current_time);
// 当前月份每天的起始时间
$this->current_mouth_last_day = date('t');
}
public function project_contrast()
{
if (request()->isGet()) {
try{
} catch (\Exception $e) {
$result = self::$param_error;
$result['msg'] = $e->getMessage();
$result['line'] = $e->getLine();
$result['file'] = $e->getFile();
return json()->data($result);
}
} else {
$result = $this->return_code(self::$error);
return json()->data($result);
}
}
/**
* 获取今天的起始时间
* @return mixed
* author: 划水小老虎
*/
public function get_this_day_start_end_time()
{
$this_data_start_end_time['start_time'] = strtotime('Y-m-d', $this->current_time);
$this_data_start_end_time['end_time'] = $this_data_start_end_time['start_time']+60*60*24-1;
return $this_data_start_end_time;
}
/**
* 获取本周每天的起止时间
* @return mixed
* author: 划水小老虎
*/
public function get_this_week_day_start_end_time()
{
// 本周开始日期
$time = date('d',strtotime('last Monday', $this->current_time));
for ($i = 0;$i<=7;$i++) {
$is = $time+$i;
$current_day = $this->current_year.'-'.$this->current_mouth.'-'.$is;
$this_week_day_start_end_time[$i] = [
'start_time' => strtotime($current_day),
'end_time' => strtotime($current_day)+60*60*24-1,
];
}
return $this_week_day_start_end_time;
}
/**
* 获取本月每天的起止时间
* @return mixed
* author: 划水小老虎
*/
public function get_this_mouth_day_start_end_time()
{
// 当前月份每天的起始时间戳
for ($i = 1;$i<= $this->current_mouth_last_day ;$i++) {
$this_mouth_all_day[$i]['start_time'] = mktime(00, 00, 00, $this->current_mouth, $i);
$this_mouth_all_day[$i]['end_time'] = mktime(23, 59, 59, $this->current_mouth, $i);
}
return $this_mouth_all_day;
}
/**
* 获取本周的起止时间戳
* @return mixed
* author: 划水小老虎
*/
public function get_this_week_start_end_time()
{
// 获取本周开始结束时间戳
$time = strtotime('last Monday', $this->current_time);
$this_week_start_end_time['start_time'] = date('Y-m-d 00:00:00', $time);
$this_week_start_end_time['end_time'] = date('Y-m-d 23:59:59', strtotime('Sunday', $time));
return $this_week_start_end_time;
}
/**
* 获取本月每周的起始时间
* @return mixed
* author: 划水小老虎
*/
public function get_this_mouth_week_start_end_time()
{
// 当前月份每周的起始时间戳
for ($i = 1;$i<= $this->current_mouth_last_day;$i++) {
$this_mouth_all_day[$i]['start_time'] = mktime(00, 00, 00, $this->current_mouth, $i);
$this_mouth_all_day[$i]['end_time'] = mktime(23, 59, 59, $this->current_mouth, $i);
}
return $this_mouth_all_day;
}
/**
* 获取本月的起止时间
* @return mixed
* author: 划水小老虎
*/
public function get_this_mouth_start_end_time()
{
$this_mouth_start_end_time['start_time'] = mktime(0,0,0,date('m'),1,date('Y'));
$this_mouth_start_end_time['end_time'] = mktime(23,59,59,date('m'),date('t'),date('Y'));
return $this_mouth_start_end_time;
}
/**
* 获取本年每月的起始时间
* author: 划水小老虎
*/
public function get_this_year_mouth_start_end_time()
{
// 今年每个月份的起始时间
for ($i = 1;$i <= 12;$i++) {
$this_year_mouth_start_end_time[$i]['start_time']=mktime(00, 00, 00, date($i, strtotime($current_time)), 01);
$this_year_mouth_start_end_time[$i]['end_time']=mktime(23, 59, 59, date($i, strtotime($current_time))+1, 00);
}
return $this_year_mouth_start_end_time;
}
/**
* 获取本年每个季度的起始时间戳
* @return mixed
* author: 划水小老虎
*/
public function get_this_year_quarter_start_end_time()
{
for($i = 1;$i <= 4;$i++)
{
$this_year_quarter_start_end_time[$i]['start_time']=mktime(0, 0, 0,$i*3-3+1,1,date('Y'));
$this_year_quarter_start_end_time[$i]['end_time']=mktime(23,59,59,$i*3,date('t',mktime(0, 0 , 0,1*3,1,date("Y"))),date('Y'));
}
return $this_year_quarter_start_end_time;
}
时间戳计算获取今天起始本周每天起止本月每天起止本周起止本月每周起始时间本年每月起止时间本年每个季度的起止时间
最新推荐文章于 2022-08-09 11:18:35 发布