再做日期规范化, 因为6月没有31号, 所以就好像2点60等于3点一样, 6月31就等于了7月1 是不是逻辑很”清晰”呢? , 都可能会有这个迷惑, 我们也可以很轻松的验证类似的其他月份, 印证这个结论: var_dump(date("Y-m-d", strtotime("-1 month", strtotime("2017 -03-31"))));//输出2017-03-03var_dump(date("Y-m-d", strtotime("+1 month", strtotime("2017-08-31"))));//输出 (date("Y-m-d", strtotime("last month", strtotime("2017-03-31"))));//输出2017-03-03 那怎么办呢? day of +1 month", strtotime("2017-08-31"))));////输出2017-09-01var_dump(date("Y-m-d", strtotime("first
$t = strtotime("-{$n} days 00:00:00");//当前日期的前n天的0点 $t = strtotime("-{$n} days 23:00:00");//当前日期的前n天的 strtotime("+{$n} days 00:00:00");//当前日期的后n天的0点 $t = strtotime("+{$n} days 23:00:00");//当前日期的后n天的23点 获取指定日期前 $n*86400 s的时间 $t = strtotime("+{$n} days {$data} 00:00:00");//当前日期的后n天的0点 $t = strtotime("+{$n} days "); $t = strtotime("yesterday 00:00:00"); //以上三个结果一样,但是为了严谨期间,如果需要时分秒,给出精确时间 $t = strtotime("tomorrow "); $t = strtotime("tomorrow midnight"); $t = strtotime("tomorrow 00:00:00"); $year = 2015; $month =
var_dump(date('Y-m-d')); var_dump(date('Y-m-d', strtotime('- 1 day'))); var_dump(date('Y-m-d', strtotime ('+ 2 day'))); var_dump(date('Y-m-d', strtotime('- 1 week'))); var_dump(date('Y-m-d', strtotime('+ 2 02" string(10) "2018-10-23" 上面的这些都没有问题,毕竟day和week的时间是固定的,但是month就不一样了,有大月和小月 var_dump(date("Y-m-d", strtotime ("-1 month", strtotime("2018-05-31")))); 打印出来的结果是: string(10) "2018-05-01" !!! ("last day of -1 month", strtotime("2018-05-31")))); 打印结果是: string(10) "2017-04-30" 为了避免 strtotime 引起的问题
():把字符串类型日期格式转成时间戳 使用函数strtotime(),打印前一天日期,参数:String类型 “-1 day” echo date("Y-m-d H:i:s",strtotime("-1day "));输出 2016-05-12 15:27:33 使用函数strtotime(),打印明天日期,参数:String类型 “+1 day” echo date("Y-m-d H:i:s",strtotime s",strtotime("+1 week"));;输出 2016-05-20 15:29:35 使用函数strtotime(),打印下一个月日期,参数:String类型 “+1 month” echo date("Y-m-d H:i:s",strtotime("+1 month")); 输出:2016-06-13 15:37:42 使用函数strtotime(),打印下周一日期,参数:String类型 “last Mondy” echo date("Y-m-d H:i:s",strtotime("next Monday")); 输出:2016-05-16 00:00:00 使用函数strtotime
###获取今日0点的时间戳 $today = strtotime(date('Ymd')); $today2 = strtotime('today'); echo "today = ". $today2; 输出: today = 1463500800 today2 = 1463500800 由此可见,获取今日0点时的时间戳可以直接使用strtotime("today").
59', strtotime("$startstr +6 day"))); $Monthend = strtotime(date('Y-m-d 23:59:59', strtotime("$startstr 0, $month, $firstWeekDay + 1, $year); $endThisweek = mktime(23, 59, 59, $month, $firstWeekDay + 7, * 86400), ($endThisweek + ($i - 2) * 7 * 86400)]; } //获取每周的时间节点 $weekArray[$weeknum] = [$ /86400)/7; $days3 = (int)floor($days2); $length = $days3+1; for($i=2;$i<=$length;$i++) { 59', strtotime("$startstr +6 day"))); $Monthend = strtotime(date('Y-m-d 23:59:59', strtotime("$startstr
= $end_add = 0; $start_N = date(‘N’,strtotime($start_date)); $start_reduce = ($start_N == 7) ? 1 : 0; $end_N = date(‘N’,strtotime($end_date)); in_array($end_N,array(6,7)) && $end_add = ($end_N = = 7) ? 2 : 1; $days = abs(strtotime($end_date) – strtotime($start_date))/86400 + 1; return floor(($days + $start_N – 1 – $end_N) / 7) * 2 – $start_reduce + $end_add; } echo get_weekend_days(date(“Y-m-d H:i:
endThisweek=time(); //获取上周起始时间戳和结束时间戳 $beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7, date('Y')); $endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')); //获取本月起始时间戳和结束时间戳 (date('Y-m-01 00:00:00',strtotime('-1 month'))); //$end_time = strtotime(date("Y-m-d 23:59:59", strtotime day'))); $begin_year = strtotime(date("Y",time())."-1". "-1"); //本年开始 $end_year = strtotime(date("Y",time())."-12".
将年月日时间转换成时间戳 echo strtotime('2020-01-15 11:20:10'); //直接输出转换后的时间戳 当前时间加七天 echo date("Y-m-d H:i:s",strtotime ("+7 day")); //输出七天后的日期 php获取今天日期 date("Y-m-d",strtotime("today")); //strtotime(‘today’)输出今天的开始时间戳 date ("Y-m-d",time()); //time()输出当前秒时间戳 php获取昨天日期 date("Y-m-d",strtotime("-1 day")); date("Y-m-d",strtotime ")); //二者都可以实现 php获取7天后日期 date("Y-m-d",strtotime("+7 day")); 以此类推,需要获取多久后的日期就+多少day即可! date('Y')); mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')); //php获取本月起止时间戳 mktime(0,0,0
$day = '2014-03-28'; $d1 = date("Y-m-d", strtotime("0 day $day"));//第1天03-28 $d3 = date("Y-m-d", strtotime("2 day $day"));//第3天 $d7 = date("Y-m-d", strtotime("6 day $day"));//第7天 $d15 = date("Y-m-d ", strtotime("14 day $day"));//第15天 $d30 = date("Y-m-d", strtotime("29 day $day"));//第30天 $rd5 = date ("Y-m-d", strtotime("-4 day $day"));//最后5天 $rd3 = date("Y-m-d", strtotime("-2 day $day"));//最后3天 $rd2 = date("Y-m-d", strtotime("-1 day $day"));//最后2天 $rd1 = date("Y-m-d", strtotime("-0 day $day")
7 : date('w')) - 1) * 24 * 3600)); //w为星期几的数字形式,这里0为周日 //本周日 echo date('Y-m-d', (time() + (7 - (date 7 : date('w'))) * 24 * 3600)); //同样使用w,以现在与周日相关天数算 //上周一 echo date('Y-m-d', strtotime('-1 monday', strtotime生成 //本月最后一日 echo date('Y-m-d', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00')); //t为当月天数,28至31天 //上月一日 echo date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m ', time()) . '-01 00:00:00'))); //本月一日直接strtotime上减一个月 //上月最后一日 echo date('Y-m-d', strtotime(date(
echo strtotime("2014-03-27"), "\n"; echo strtotime("December 31"), "\n"; echo strtotime("now"), "\n"; echo strtotime("10 September 2000"), "\n"; echo strtotime("+1 day"), "\n"; echo strtotime("+1 week") :i:s', time()); echo strtotime($time.'1day'), "\n"; echo "\n"; echo strtotime($time N的取值范围是1-7 echo date('Y-m-d H:i:s',strtotime('2014W01-5')), "\n"; //2014年第一周的第五天 //2014-01-03 00:00:00 2] => 12 [3] => 27 [4] => 2 [5] => 114 [6] => 4 [7] => 85 [8] => 0 ) 如果第二参数为真
7 : date('w')) - 1) * 24 * 3600)); //w为星期几的数字形式,这里0为周日 //本周日 echo date('Y-m-d', (time() + (7 - (date 7 : date('w'))) * 24 * 3600)); //同样使用w,以现在与周日相关天数算 //上周一 echo date('Y-m-d', strtotime('-1 monday', strtotime生成 //本月最后一日 echo date('Y-m-d', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00')); //t为当月天数,28至31天 //上月一日 echo date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m ', time()) . '-01 00:00:00'))); //本月一日直接strtotime上减一个月 //上月最后一日 echo date('Y-m-d', strtotime(date(
今天遇到一个BUG,在使用strtotime(date('Y-m-d') . ' 00:00:00') 获取当天零点时间戳会出现不准确的问题,有时候获取的是正常的零点时间戳,有时候获取的是当天8点的时间戳 解决方案: strtotime(date('Y-m-d')) // 获取当天零点时间戳 strtotime(date('Y-m-d') . ' + 1 day') - 1 // 获取当天23点59分59 秒时间戳 strtotime(date('Y-m-d')) - 1 // 获取昨天23点59分59秒时间戳
echo strtotime('+7days');//输出时间戳 可以将日期输出为时间戳,1970至指定日期的时间戳秒。 echo strtotime('+7days');//输出时间戳 //time可以获取当前时间戳 echo time(); 当然也可以以指定形式输出指定日期 tring date($format[,$ timestamp]),[]内的可以使用strtotime输出指定日期 实例 <? php date_default_timezone_set('Asia/Shanghai');//设置默认时区,为上海 //年月日格式输出7天后日期 echo date('Y-m-d',strtotime ('+7days')); //strtotime('');函数才参数输出指定日期英文形式,之后用+,之前用- 取整函数 1.直接取整,舍弃小数,保留整数:intval(); 2.四舍五入取整:round
$day6;
$date7=$yue."-". $day7;
$weekarray=array("日","一","二","三","四","五","六");
$week1=$weekarray[date("w",strtotime("$date1")) ];
$week2=$weekarray[date("w",strtotime("$date2"))];
$week3=$weekarray[date("w",strtotime("$date3"))] $week6=$weekarray[date("w",strtotime("$date6"))];
$week7=$weekarray[date("w",strtotime("$date7"))]; 星期 $week7
";
?
4)按年 生成范围 3,所用语言是 php,服务器解析需要安装 Apache,或者 Nginx; 4,格式是时间戳,切记,拥有时间戳,就可以任意处理,可以生产这种日期时间格式: 2016-7- php 2 /** 3 * Created by PhpStorm. 4 * Author: 林冠宏 5 * Date: 2016/6/4 6 * Time: 16:06 7 function TimeRangeHelper(){ 28 $this->DayTime = 24*60*60; 29 $this->WeekTime = 7* GetTimeRang("月"); 48 $this->GetTimeRang("月","2015-5"); 49 $this->GetTimeRang("月","2016-7" )); // 获取传过来的月所有天数 152 $timeF = strtotime($selectTime); 153 } 154 $timeL
// $stage['start_last_week']=date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')-date('w')+1-7, // $stage['end_last_week']=date("Y-m-d H:i:s",mktime(23,59,59,date('m'),date('d')-date('w')+7- 7,date('Y'))); /** * 获取某月所有时间 * @param string $time 某天时间戳 * @param string $format 转换的时间格式 * $i++){ $date[$i] = date($format ,strtotime( '+' . $m=1:$m=$m; $firstday=strtotime($y.
1. strtotime 函数strtotime函数用于将人类可读的日期和时间字符串转换为 Unix 时间戳。它可以接受一个日期时间字符串作为参数,并尝试解析它并将其转换为对应的 Unix 时间戳。 以下是strtotime函数的参数和作用:strtotime(string $datetime, ? echo strtotime("2023-08-06 15:30:00"), PHP_EOL;echo strtotime("tomorrow"), PHP_EOL;echo strtotime("+1 ');// Prints: July 1, 2000 is on a Saturdayecho "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, DATE_RFC2822);// prints something like: 2000-07-01T00:00:00+00:00echo date(DATE_ATOM, mktime(0, 0, 0, 7,
本文操作环境:windows7系统、PHP5.6版,DELL G3电脑。 strtotime() strtotime() 函数用于将英文文本字符串表示的日期转换为时间戳,为 date() 的反函数,成功返回时间戳,否则返回 FALSE 。 php echo strtotime(“2009-10-21 16:00:10”); //输出 1256112010 echo strtotime(“10 September 2008”); //输出 1220976000 echo strtotime(“+1 day”), “ “; //输出明天此时的时间戳 ? > 自定义函数 下面的函数与strtotime功能差不多。<?