PHP 获取时间差函数汇总
来源:互联网 发布:第三方服务商淘宝客 编辑:程序博客网 时间:2024/06/06 20:00
//获取当天的星期(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'))
$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获取当前时间差8小时
- linux获取时间函数及计算时间差
- linux获取时间函数及计算时间差
- MySQL时间函数-获取当前时间-时间差
- PHP取得日期时间差通用函数
- 获取时间差
- PHP获取当前时间差8小时的问题
- PHP获取当前时间差8小时的问题
- PHP获取当前时间差8小时的问题
- PHP字符串函数汇总
- php常用函数汇总
- php 字符串函数汇总
- PHP常用函数汇总
- asp.net 获取网站根目录总结
- 从ads到keil
- linux内核学习之网络篇——通过socket通信
- Win7下.NET应用程序System.IO.FileNotFoundException问题
- Uboot中start.S源码的指令级的详尽解析 在线版
- PHP 获取时间差函数汇总
- 结构体字节对齐
- boost test
- jQuery中load的使用
- MonkeyRunner_Testing app example(1)
- 【Author : DS & MZ】 2012 ACM-ICPC 杭州网络预赛
- 在运行时修改视图
- jQuery 和 prototype 选择器的使用与注意事项
- Liferay Portal 6学习笔记1:Portal介绍