PHP100个知识点之2 日期时间(二)
来源:互联网 发布:网络名誉侵权救济 编辑:程序博客网 时间:2024/05/22 09:42
1.time这个返回当前时间戳
<?php
//time()-返回自从Unix纪元以来所经过的秒数(1970-1-1 00:00:00 GMT)
$nextweek=time()+(7*24*60*60);
echo '下周:'.date('Y-m-d',$nextweek);
?>
//time()-返回自从Unix纪元以来所经过的秒数(1970-1-1 00:00:00 GMT)
$nextweek=time()+(7*24*60*60);
echo '下周:'.date('Y-m-d',$nextweek);
?>
2.strtotime()根据字符串得到一个时间戳,更直观些相比用time()的计算表达式
<?php
echo strtotime("now")."<br/>";
echo time();
?>
echo strtotime("now")."<br/>";
echo time();
?>
这2个等价的。
如下使用
1.)
<?php
//7天前
echo '7天前:'.date('Y-m-d',strtotime('7 days ago'));
echo '<br/>';
//今天
echo '今天:'.date('Y-m-d',strtotime('now'));
echo '<br/>';
//7天后
echo '7天后'.date('Y-m-d',strtotime('7 days'));
?>
//7天前
echo '7天前:'.date('Y-m-d',strtotime('7 days ago'));
echo '<br/>';
//今天
echo '今天:'.date('Y-m-d',strtotime('now'));
echo '<br/>';
//7天后
echo '7天后'.date('Y-m-d',strtotime('7 days'));
?>
结果:
7天前:2008-09-22
今天:2008-09-29
7天后2008-10-06
今天:2008-09-29
7天后2008-10-06
或者用这个也行:
<?php
//7天前
echo '7天前:'.date('Y-m-d',strtotime('1 week ago'));
echo '<br/>';
//今天
echo '今天:'.date('Y-m-d',strtotime('now'));
echo '<br/>';
//7天后
echo '7天后'.date('Y-m-d',strtotime('1 week'));
?>
//7天前
echo '7天前:'.date('Y-m-d',strtotime('1 week ago'));
echo '<br/>';
//今天
echo '今天:'.date('Y-m-d',strtotime('now'));
echo '<br/>';
//7天后
echo '7天后'.date('Y-m-d',strtotime('1 week'));
?>
n周前后:
<?php
//2周前
echo '2周前:'.date('Y-m-d',strtotime('2 weeks ago'));
echo '<br/>';
//今天
echo '今天:'.date('Y-m-d',strtotime('now'));
echo '<br/>';
//2周后
echo '2周后'.date('Y-m-d',strtotime('2 weeks'));
?>
//2周前
echo '2周前:'.date('Y-m-d',strtotime('2 weeks ago'));
echo '<br/>';
//今天
echo '今天:'.date('Y-m-d',strtotime('now'));
echo '<br/>';
//2周后
echo '2周后'.date('Y-m-d',strtotime('2 weeks'));
?>
2.)
<?php
//103天之后
echo '103天之后是:'.date('Y-m-d',strtotime('+103 days'));
echo '<br/>';
//下周三
echo '下周三:'.date('Y-m-d',strtotime('next Wednesday'));
?>
//103天之后
echo '103天之后是:'.date('Y-m-d',strtotime('+103 days'));
echo '<br/>';
//下周三
echo '下周三:'.date('Y-m-d',strtotime('next Wednesday'));
?>
输出:
103天之后是:2009-01-10
下周三:2008-10-01
下周三:2008-10-01
- PHP100个知识点之2 日期时间(二)
- PHP100个知识点之2 日期时间(一)
- 时间日期格式化小知识点
- SAS学习笔记之日期、时间(二)
- 【MySQL数据类型2之--日期时间类型】
- 工具之时间/日期
- JAVA之日期时间
- php之时间日期
- Qt之日期时间
- Qt之日期时间
- sql截取日期时间,将日期和时间分开成2个字段
- php100视频之Ajax+PHP打造等待进度条效果(二)【49讲】
- C#知识点之二
- Canvas知识点之二
- perl比较2个日期相差的时间
- BOOST 日期时间库 之 日期长度与日期区间 2/3
- 日期时间函数之细节
- python之日期和时间
- PHP100个知识点之2 日期时间(一)
- (转)Android画图学习总结(五)——Paint
- linux查找类命令使用(备忘)
- 5.1 损坏联机日志的恢复方法
- Linux启动为什么没有先执行main函数
- PHP100个知识点之2 日期时间(二)
- 闪电算法
- Android permission权限列表
- CareerCup 17.12 Pair sum equal to a fixed value
- 海量数据处理面试题集锦
- Raspberry Pi平台上编译XBMC的方法
- struts通过注解与jQuery进行action请求
- 批处理修改文件名
- Struts2文件上传(一)