<?php echo "今天:".date("Y-m-d")."
"; echo "昨天:".date("Y-m-d",strtotime("-1 day")), "
"; echo "明天:".date("Y-m-d",strtotime("+1 day")). "
"; echo "一周后:".date("Y-m-d",strtotime("+1 week")). "
"; echo "一周零两天四小时两秒后:".date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")). "
"; echo "下个星期四:".date("Y-m-d",strtotime("next Thursday")). "
"; echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."
"; echo "一个月前:".date("Y-m-d",strtotime("last month"))."
"; echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."
"; echo "十年后:".date("Y-m-d",strtotime("+10 year"))."
"; strtotime()函数的作用是将日期时间描述解析为 Unix 时间戳 int strtotime ( string time [, int now] ) ?>
此函数期望接受包含英国日期格式的字符串,并尝试将其解析为相对于 now 参数给出的时间的 Unix 时间戳(自 1970 年 1 月 1 日 00:00:00 GMT 以来的秒数),如果未提供此参数php取时间戳,使用当前系统时间。
-------------------------------------------------- -----------------
PHP获取前天和今天日期的代码
前天去笔试的时候也是这样,但当时就想不起来了。 我只记得 date_sub(now(),'interval 1 day');date('Y/m/dh:i:s',mktime on MYSQL (date('h'), date('i'), date( 's'), 日期('m') , 日期('d')+1, 日期('Y')));
-------------------------------------------------- ------------------------------------------
首先获取明天的 UNIXTIME
然后除以三天或三天的秒
将减去的 UNIXTIME 转换为日期。
-------------------------------------------------- ------------------------------------------
引用如下:
<?php date_default_timezone_set('Asia/Shanghai'); #昨天 echo date("Y/m/d h:i:s",time()-24*60*60); echo "
"; #前天 echo date("Y/m/d h:i:s",time()-2*24*60*60); ?>
-------------------------------------------------- ------------------------------------------
向上
-------------------------------------------------- ------------------------------------------
方法有很多,我介绍一种:
date("年/月/日 H:i:s", strtotime("1 天前"));
date("年/月/日 H:i:s", strtotime("2 天前"));
-------------------------------------------------- ------------------------------------------
日期("年/月/日 H:i:s",mktime(0,0,0,日期("m"),日期("d")-1,日期("Y")));
-------------------------------------------------- ------------------------------------------
以前数时间总是很恶心php取时间戳,呵呵,我学会后,下面是下周的当前时间。
date_default_timezone_set('亚洲/上海');
$tmp = 时间()+60*60*24*7;
打印日期(“月/日/年:i:s”,$tmp);
-------------------------------------------------- ------------------------------------------
再补充一张:
$time_yes=本地时间(time()-24*60*60, true);
$time_b_yes=本地时间(time()-2*24*60*60, true);
$昨天=$time_yes['tm_mday'];
$the_day_before_yes=$time_b_yes['tm_mday'];
-------------------------------------------------- ------------------------------------------
time() - 86400 昨天的
引用如下: