获取前 n 天或者后 n 天的日期
下面举了三个实现有计算n天以前的日期和获取指定日期前的N天,最后还有个js代码.
- $rs['expire_long']=5;
- echo date("Y-m-d H:i:s",strtotime('-'.$rs['expire_long'].' days',strtotime('2011-01-01 10:28:18')));
- <?
- //========计算n天以前的日期subolddate()=====================
- function subolddate($day){
- $now=time();
- $m=$day*24*60*60;
- $diff=$now-$m;
- $oldday=date( "Y-m-d ",$diff);
- echo $day. "天以前是 ".$oldday;
- }
- //========================================================
- subolddate(5);
- ?>
js实现方法:
- <script type="text/javascript">
- function showdate(n)
- {
- var uom = new Date(new Date()-0+n*86400000);
- uom = uom.getFullYear() + "-" + (uom.getMonth()+1) + "-" + uom.getDate();
- return uom;
- }
- window.alert("今天是:"+showdate(0));
- window.alert("昨天是:"+showdate(-1));
- window.alert("明天是:"+showdate(1));
- window.alert("10天前是:"+showdate(-10));
- window.alert("5天后是:"+showdate(5));
- </script>
新闻热点
疑难解答