//获得当前时间
//date()格式化时间返回String类型。 date("Y-m-d H:i:s")
$current_date = date(’Y-m-d’,time());
//根据当前时间加一周后
$weekLater = date(’Y-m-d’,strtotime("$current_date + 1 week"));
echo $weekLate;
// 2009-05-26 加一天的日期
$tomorrow = date(’Y-m-d’,strtotime("2009-05-26 + 1 day"));
echo $tomorrow; // 2009-05-27
也可以这样 date("Y-m-d",strtotime("-1 day")) ;直接获得前一天时间
用此方法date(“Y-m-d”, strtotime(“-1 month”))得到上个月的日期时是有问题存在的。问题就出在当前月如果有30,31号时用此方法获取上月会出错。比如你在1月30号或1月31号时用此方法得到上月的月份会显示还是1月份。因此,采用这个函数自动获取上个月的记录则出错。还是笨办法解决:
if (date("n") == 1) {
$tmpMonth = 12;
$tmpYear = date ("Y") - 1;
}else{
$tmpMonth = date ("n") - 1;
$tmpYear = date ("Y");
}
$tmpDate = "$tmpYear-$tmpMonth-1";
php 获取今天第一秒和最后一秒的时间戳
获取第一秒的时间戳
$firstSeconds = strtotime(date("Y-m-d 00:00:00"));
//或者
$firstSeconds = strtotime(date("Y-m-d"));
获取最后一秒的时间戳
$lastSeconds = strtotime(date("Y-m-d 23:59:59"));
--------------------------------------------------------------------------------------------------------------------------------------------------------
查询时间的 一天的开始 和一天的结束
//订单时间 $order_create_time = $order_info['create_time'];//2020-05-25 10:56:58 $year = substr($order_create_time,0,4); $month = substr($order_create_time,5,2); $day = substr($order_create_time,8,2); $order_create_start_time= ($year.'-'.$month.'-'.$day.' '.'00'.':'.'00'.':'.'00'); $order_create_end_time= ($year.'-'.$month.'-'.$day.' '.'23'.':'.'59'.':'.'59'); //dump($order_create_start_time); // dump($order_create_end_time);die; $today_start_time = date('Y:m:d 00:00:00'); $today_start_time_str = strtotime(date('Y:m:d 00:00:00')); $today_end_time = date('Y:m:d 23:59:59'); if(strtotime($order_create_time) < $today_start_time_str){ //echo '过去'; $order_info_all = Db::name('order')->where('jl_market_address_id',$v)->whereTime('create_time', 'between', [$order_create_start_time, $order_create_end_time])->select(); }else{ // echo '现在'; $order_info_all = Db::name('order')->where('jl_market_address_id',$v)->whereTime('create_time', 'between', [$today_start_time, $today_end_time])->select(); }