PHP输出时间差函数代码
来源:互联网 发布:张家港淘宝拍卖会 编辑:程序博客网 时间:2024/05/17 07:24
在学习PHP 的时候,经常会用到获取现在之前或之后,某个时间段的日期。
PHP输出时间差函数
例2,
PHP输出时间差函数
<?php date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time()),"<br>"; echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>"; echo "昨天:",date("Y-m-d",strtotime("-1 day")), "<br>"; echo "明天:",date("Y-m-d",strtotime("+1 day")), "<br>"; echo "一周后:",date("Y-m-d",strtotime("+1 week")), "<br>"; echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>"; echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")), "<br>"; echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>"; echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>"; echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>"; echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>"; ?>
例2,
<?php//获取当天的星期(1-7)function GetWeek($times){ $res = date('w', strtotime($times)); if($res==0) $res=7; return $res;}//获取当天时间function GetTime($times){ $res = date('H:i', strtotime($times)); return $res;}//获取现在过几月的的时间function GetMonth($Month,$type='l'){ if(!strcmp($type,'b')) $res=date("Y-m-d H:i:s",strtotime("-$Month months")); if(!strcmp($type,'l')) $res=date("Y-m-d H:i:s",strtotime("+$Month months")); return $res;}//获取当前时间function GetCurrentDateTime(){ $res=date("Y-m-d H:i:s",time()); return $res;}//获取当前时间隔几小时之前或之后的时间function GetDiffHours($hours,$type='l'){ if(!strcmp($type,'b')) www.jbxue.com $res=date("Y-m-d H:i:s",strtotime("-$hours hour")); if(!strcmp($type,'l')) $res=date("Y-m-d H:i:s",strtotime("+$hours hour")); return $res; }//间隔几分钟之前或之后的时间function GetDiffMinute($Minute,$type='l'){ if(!strcmp($type,'b')) $res=date("Y-m-d H:i:s",strtotime("-$Minute minute")); if(!strcmp($type,'l')) $res=date("Y-m-d H:i:s",strtotime("+$Minute minute")); return $res; }//间隔几秒之前或之后的时间function GetDiffSec($sec,$type='l'){ if(!strcmp($type,'b')) $res=date("Y-m-d H:i:s",strtotime("-$sec second")); if(!strcmp($type,'l')) $res=date("Y-m-d H:i:s",strtotime("+$sec second")); return $res; }//间隔几个星期之前或之后的时间function GetDiffWeek($Week,$type='l'){ if(!strcmp($type,'b')) $res=date("Y-m-d H:i:s",strtotime("-$Week week")); if(!strcmp($type,'l')) $res=date("Y-m-d H:i:s",strtotime("+$Week week")); return $res; }// 间隔几天之间的时间function GetDiffDays($days,$type='l'){ if(!strcmp($type,'b')) $res=date("Y-m-d H:i:s",strtotime("-$days day")); if(!strcmp($type,'l')) $res=date("Y-m-d H:i:s",strtotime("+$days day")); return $res; }//间隔几年之前或之后的时间function GetDiffYears($year,$type='l'){ if(!strcmp($type,'b')) $res=date("Y-m-d H:i:s",strtotime("-$year year")); if(!strcmp($type,'l')) $res=date("Y-m-d H:i:s",strtotime("+$year year")); return $res; }
- PHP输出时间差函数代码
- php输出时间差
- PHP获取时间差函数
- PHP 获取时间差函数汇总
- PHP 获取时间差函数汇总
- php计算时间差,输出友好时间显示
- PHP常用的代码检测输出函数
- PHP取得日期时间差通用函数
- PHP 输出HTML代码
- PHP DATE( )函数与系统时间差8小时解决办法
- PHP DATE( )函数与系统时间差8小时解决办法
- PHP DATE( )函数与系统时间差8小时解决办法
- PHP输出打印函数
- PHP中的输出函数
- PHP之输出函数
- php一些输出函数
- 如何输出高精度时间差
- 标准格式输出时间差
- Lesson1: Windows程序运行原理及程序编写流程
- ThinkPHP中FCKeditor编辑器的使用方法
- 嵌入式Linux调试方法
- PHP 正则表达式函数库(两套)
- 你具备当老板的创业素质吗
- PHP输出时间差函数代码
- 卡特兰数
- 函数指针和指针函数
- Compiling,Error spawning cl.exe在visual c++编译器出现是的解决办法
- 转:移动建站工具(一):分秒钟将Web网站移动化
- 一些语言细节(1)
- hdu 4391
- Valid Number
- 搬运工--C关键字union/const/define/typedef/extern/volatile