
<? php
回显“今天: ”. 日期(“ Y-m-d”). “
”;
回显“昨天: ”. 日期(“ Y-m-d”,strtotime(“-1天”)),“
”;
回显“明天: ”. 日期(“ Y-m-d”php 0点时间戳,strtotime(“ + 1天”)). “
”;
回显“一周后: ”. 日期(“ Y-m-d”,strtotime(“ + 1周”)). “
”;
回显“一周后,两天零四个小时零两秒: ”. 日期(“ Ymd G: H: s”,strtotime(“ + 1周2天4小时2秒”)). “
”;
回显“下周四: ”. 日期(“ Y-m-d”,strtotime(“下周四”)). “
”;
回显“上周一: ”. 日期(“ Y-m-d”,strtotime(“上周一”)). “
”;
回显“一个月前: ”. 日期(“ Y-m-d”,strtotime(“上个月”)). “
”;
回显“一个月后: ”. 日期(“ Y-m-d”,strtotime(“ + 1个月”)). “
”;
回声“十年后: ”. 日期(“ Y-m-d”,strtotime(“ + 10年”)). “
”;
strtotime()函数的功能是将日期和时间描述解析为Unix时间戳
intstrtotime(字符串时间[,现在为int])

?>
此函数期望接受包含美国英语日期格式的字符串php 0点时间戳,并尝试将其解析为Unix时间戳,该时间戳的值是相对于now参数Time给出的(如果未提供此参数,则为当前系统时间)使用.
--------------------------------------------------- --------------------
使用PHP获取前天和昨天的代码
前天我去面试时也是一样,但当时我不记得了. 只要记住date_sub(now(),'interval 1 day');日期(MYSQL中的日期('Y / m / dh: i: s'),mktime(日期('h'),日期('i'),日期('s'),日期('m'),日期('d ')+ 1,日期('Y'))); <
--------------------------------------------------- ---------------------------------
立即获取UNIXTIME
然后减去一两天的时间
将减去的UNIXTIME格式化为日期.
--------------------------------------------------- ---------------------------------
以下是引用的内容:
<? php
date_default_timezone_set(“亚洲/上海”);

#昨天
回显日期(“ Y / m / d h: i: s”,时间()-24 * 60 * 60);
echo“
”;
#前天
回显日期(“ Y / m / d h: i: s”,时间()-2 * 24 * 60 * 60);
?>
--------------------------------------------------- ---------------------------------
上
--------------------------------------------------- ---------------------------------
有很多方法,我也介绍一种:
date(“ Y / m / d H: i: s”,strtotime(“ 1天前”));
date(“ Y / m / d H: i: s”,strtotime(“ 2天前”));
--------------------------------------------------- ---------------------------------
date(“ Y / m / d H: i: s”,mktime(0,0,0,日期(“ m”),日期(“ d”)-1,日期(“ Y”))) ;
--------------------------------------------------- ---------------------------------
过去很讨厌计算时间. 哈哈,我学到了. 这是下周的当前时间.
date_default_timezone_set(“亚洲/上海”);
$ tmp = time()+ 60 * 60 * 24 * 7;
打印日期(“ m / d / Y H: i: s”,$ tmp);
--------------------------------------------------- ---------------------------------
再添加一个:
$ time_yes = localtime(time()-24 * 60 * 60,true);
$ time_b_yes = localtime(time()-2 * 24 * 60 * 60,true);
$昨天= $ time_yes ['tm_mday'];
$ the_day_before_yes = $ time_b_yes ['tm_mday'];
--------------------------------------------------- ---------------------------------

昨天()-86400时间
以下是引用的内容:
<?
//昨天
打印日期(“ Y-m-d”,strtotime(“-1天”));
//上周
打印日期(“ Y-m-d”,strtotime(“-1周”));
//上个月
打印日期(“ Y-m-d”,strtotime(“-1月”));
//去年
打印日期(“ Y-m-d”,strtotime(“-1年”));
?>
--------------------------------------------------- ---------------------------------
strtotime得到一个时间戳,然后自己格式化.
strtotime(“昨天”);
strtotime(“-2天”);
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-164403-1.html
即使不与我们结盟
哈哈
把市值抬上天