PHP中strtotime函数用法
来源:互联网 发布:淘宝装修工具 编辑:程序博客网 时间:2024/06/05 12:50
[导读] strtotime函数在php中是可以把日志转换成时间戳,他可以方便的让我们对日期时间分秒的计算,下面我来给各位介绍时strtotime函数用法,有需要的同学可参考。1 获取当前的时间的时间戳!a 实用strtotime(now);来获
strtotime函数在php中是可以把日志转换成时间戳,他可以方便的让我们对日期时间分秒的计算,下面我来给各位介绍时strtotime函数用法,有需要的同学可参考。1.获取当前的时间的时间戳!
a.实用strtotime('now');来获取当前的时间戳!(因为PHP当前时间和真是时间相差8小时)
代码如下复制代码1 echo date('Y-m-d H:i:s',strtotime('now')+8*60*60);
结果:2013-04-05 03:15:02
b.你也可以用time() 来直接获取!
代码如下复制代码
1 echo date('Y-m-d H:i:s',time()+8*60*60);
结果:2013-04-05 03:15:02
2.获取10天之后的时间戳:
使用方法:
代码如下复制代码1 strtotime("+10 days")+8*60*60输出10天后的日期,便于查看。
代码如下复制代码1 echo date('Y-m-d H:i:s',strtotime("+10 days")+8*60*60);
结果:2013-04-15 03:15:02
3.获取一周的时间戳:
使用方法:
1 strtotime("+1 week")+8*60*60
或者你使用上面按天来获取时间戳.写法如:
代码如下复制代码strtotime("+7 days");
4.还可以获取指定几周几天几小时几秒来获取时间戳
使用方法:
代码如下复制代码1 strtotime ("+1 week 2 days 4 hours 2 seconds")+8*60*60
1 echo date('Y-m-d H:i:s',strtotime ("+1 week 2 days 4 hours 2 seconds")+8*60*60);
结果:2013-04-12 07:15:04;
5.获取上周一或者下周四的时间戳:
使用方法:
a.获取上周一的时间戳:
代码如下复制代码1 strtotime ("last Monday")+8*60*60
1 echo date('Y-m-d H:i:s',strtotime ("last Monday")+8*60*60);
结果:2013-04-01 08:00:00;
b.获取下周四的时间戳
1 strtotime ("next Thursday")+8*60*60
1 echo date('Y-m-d H:i:s',strtotime ("next Thursday")+8*60*60);
结果:2013-04-11 08:00:00;
strtotime函数比较两个时间的大小
strtotime()函数对两个固定的时间进行比较,如下:
1):定义两个固定的时间;
2):通过strtotime()函数将固定时间转换成时间戳;
3):对两个时间戳的值进行比较。
其实例代码如下:
代码如下复制代码$time="2012年11月23日15时50时20秒";
$times="2013-01-14 09:09:09";
if(strtotime($time)-strtotime($times)<0){
echo "时间:".$time." 早于时间:".$times;
}else{
echo "时间:".$times." 早于时间:".$time;
}
echo "
它们相差的时间值是:".(strtotime($time)-strtotime($times))
?>
上面的代码运行结果如下:
时间:2012年11月23日15时50时20秒 早于时间:2013-01-14 09:09:09
它们相差的时间值是:-1358125749
- PHP中strtotime函数用法
- php strtotime函数和date函数用法
- PHP函数strtotime详解
- PHP函数strtotime详解
- php函数 strtotime
- PHP strtotime函数详解
- PHP strtotime() 函数
- PHP strtotime函数详解
- PHP strtotime()函数
- PHP strtotime() 函数
- PHP strtotime() 函数
- php strtotime 用法只细节
- php中date函数和strtotime的使用
- php中date()、mktime()、strtotime()三个函数使用
- [转]PHP函数strtotime详解
- php 的strtotime的函数
- PHP的时间函数strtotime
- php strtotime 时间加减函数
- Linux的more命令使用
- C++的类型转换
- Redis学习笔记V-VM 虚拟内存 http://blog.csdn.net/zhangjhtt/article/details/6440712
- 第十一周 项目一(2)-二叉树的构造
- How should 50 red and 50 blue marbles be distributed between two jars so as to maximize the chance o
- PHP中strtotime函数用法
- GCC 中的编译器堆栈保护技术
- 计算机网络——运输层
- Java开发中JDBC连接数据库
- java基础题
- 怎么看图
- 史上最直白的logistic regression教程 之 三
- gdb 设置输入参数
- 【leetcode】【22】Generate Parentheses