php常用函数之-日期函数
来源:互联网 发布:js 清空数组 clear 编辑:程序博客网 时间:2024/06/06 16:44
php常用函数可分为三大类:日期函数、字符串函数、数组函数
记住并会运用这些函数往往可以节省很多时间。下面从日期函数开始说起:
time() microtime() date() gmdate() mktime() strtotime() checkdate
下面开始一个个详细介绍。
1 time() //返回时间戳(所谓时间戳是指从1970.1.1起到现在经过的秒数)
2 microtime() //返回时间戳(微秒),可用来计算某个程序段的运行时间。
例:$start = microtime(true);
for($i=0;$i<10000;$i++){
$temp = 13333/41;
}
$end = microtime(true);
echo $end-$start; //输出程序运行时间
3 date() //将时间戳格式化处理
例:echo date('Y-m-d 星期N h:i:s',time());
4 gmdate() //与date()的唯一区别就是:gmdate()不考虑时区
5 mktime() //将日期转换为时间戳 mktime(14,35,20,11,27,2013);
6 strtotime() //将字符串转换为时间戳,参数可以意义表示
例:strtotime('-1 day'); //前一天时间戳
strtotime('now'); //当前时间戳
strtotime('now -1 day'); // 前一天时间
7 checkdate //检测日期是否合法
例:checkdate(2,29,2000);
下面是面试中经常遇到的问题:
1 PHP打印出前一天的时间,格式是2016-5-10 22:21:30
date('Y-m-d H:i:s',strtotime('-1 day'));
或者:date('Y-m-d H:i:s',time()-24*3600);
2 求两个日期的差数 2016-5-10 ~ 2016-5-18
(strtotime('2016-5-18')-strtotime('2016-5-10'))/24*3600
- php常用函数之-日期函数
- php常用日期函数
- PHP 常用日期函数
- PHP常用日期函数
- php常用日期函数
- PHP之日期函数
- php常用函数总结-----日期
- php之日期函数(1)
- PHP基础之日期函数
- SQL常用函数之八 日期函数
- sql常用函数之日期、text函数
- ORACLE常用函数之日期函数
- MySQL常用函数之日期时间函数
- 常用函数-------日期函数
- PHP常用函数之-数组
- php常用函数之URL函数
- php常用函数之-字符串函数
- 【PHP】数组常用函数、字符串中常用函数、日期函数、数学函数
- RecyclerView添加Header的正确方式
- IDEA 报错These modules have been removed from Maven stucture
- 在github看到好的项目了,然后呢?(安卓篇)
- Hadoop API 使用介绍
- 使用通知选择城市
- php常用函数之-日期函数
- 《七天七语言》之Ruby练习1
- JMS与MQ详解
- spring源码分析(一)- 源码下载和导入eclipse
- 如何获取bind绑定的端口号
- 抽象工厂模式
- ABAP中,利用函数WS_DELIVERY_UPDATE进行VL02N发货过账时获取凭证号(mblnr)
- EasyDarwin自动停止推流
- leetcode 6. ZigZag Conversion-Zizag转换