php 30天后时间戳,php获取天周月季度的开始结束时间戳

php获取天周月季度的开始结束时间戳

首页 >

php

作者:knight

2019年11月4日 7:58 星期一

热度:455°

百度已收录

时间:2019-11-4 7:58

热度:455°

xiantiao1.png

/**

*

*/

class Test

{

/**

* 获取今天本周本月的开始结束时间戳

* @Author    zkl

* @DateTime  2019-11-04

* @copyright [copyright]

* @license   [license]

* @version   [version]

* @param     string      $type [day,week,month,quarter]

* @param     string      $time [时间]

* @return    [type]            [description]

*/

public static function getTime($type='day',$time='')

{

if (!$time) {

$time = time();

}else{

//判断是否为时间戳

$re = self::is_timestamp($time);

if (!$re) {

//不是时间戳,判断是否为日期格式,返回对应时间戳

$time = strtotime($time)?strtotime($time):time();

}

}

$result = [];

switch ($type) {

case 'day':

//获取今天开始结束时间

$dayStart = strtotime(date("Y-m-d",$time));

$dayEnd = strtotime(date("Y-m-d 23:59:59",$time));

$result = [$dayStart,$dayEnd];

break;

case 'week':

$w=date('w');

//获取本周开始日期,如果$w是0,则表示周日,减去 6 天

$first=1;

//周一

$week = date('Y-m-d H:i:s',strtotime( date("Ymd",$time)."-".($w ? $w - $first : 6).' days'));

$week_start = strtotime( date("Ymd",$time)."-".($w ? $w - $first : 6).' days');

//本周结束日期

//周天

$week_end = strtotime("{$week} +1 week")-1;

$result = [$week_start,$week_end];

break;

case 'month':

//本月第一天

$month = date('Y-m-d',strtotime(date("Ym",$time).'01'));

$month_start = strtotime(date("Ym",$time).'01');

//本月最后一天

$month_end = strtotime("{$month} +1 month")-1;

$result = [$month_start,$month_end];

break;

case 'quarter':

$season = ceil(date('n',$time) /3);

$firstday = strtotime(date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y'))));

$lastday = strtotime(date('Y-m-t',mktime(0,0,0,$season * 3,1,date('Y'))));

$result = [$firstday,$lastday];

break;

default:

//获取今天开始结束时间

$dayStart = strtotime(date("Y-m-d",$time));

$dayEnd = strtotime(date("Y-m-d 23:59:59",$time));

$result = [$dayStart,$dayEnd];

break;

}

return $result;

}

public function is_timestamp($timestamp) {

if(strtotime(date('Y-m-d H:i:s', $timestamp)) === $timestamp) {

return $timestamp;

} else {

return false;

}

}

}

var_dump(Test::getTime('week',1551683190));

700x100.gif

shang2.png

xia2.png

昵称

邮件地址 (选填)

个人主页 (选填)

checkcode.phptop2.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值