日期时间操作类
功能介绍
日期时间换算,时间戳、时间差、过去时间计算。
当前年份 currentYear()
Code phpLine:2复制1. 2.
$timer
=new
phpGrace\tools\timer();echo
$timer
->currentYear();
当前月份 currentMonth()
Code phpLine:2复制1. 2.
$timer
=new
phpGrace\tools\timer();echo
$timer
->currentMonth();
当前日期 currentDay()
Code phpLine:2复制1. 2.
$timer
=new
phpGrace\tools\timer();echo
$timer
->currentDay();
当前时 currentHour()
Code phpLine:2复制1. 2.
$timer
=new
phpGrace\tools\timer();echo
$timer
->currentHour();
当前分 currentMin()
Code phpLine:2复制1. 2.
$timer
=new
phpGrace\tools\timer();echo
$timer
->currentMin();
当前秒 currentSecond()
Code phpLine:2复制1. 2.
$timer
=new
phpGrace\tools\timer();echo
$timer
->currentSecond();
按照指定格式及指定时间戳计算时间 dateTime()
参数:
Code phpLine:2复制1. 2.
1
、$format
="Y-m-d H:i:s"
时间格式,可省参数 【默认"Y-m-d H:i:s"
】2
、$currentTime
= null//指定的时间戳,可省参数 【默认当前时间】
演示:
Code phpLine:3复制1. 2. 3.
$timer
=new
phpGrace\tools\timer();echo
$timer
->dateTime('m/d/Y H:i:s'
).'<br />'
;//当前时间
echo
$timer
->dateTime('m/d/Y H:i:s'
,1524624358
).'<br />'
;//指定时间戳
将日期时间转换时间戳 timeStamp()
参数:
Code phpLine:1复制1.
- 日期及时间,支持的格式 Y-m-d H:i:s 或 m/d/Y H:i:s
演示:
Code phpLine:2复制1. 2.
$timer
=new
phpGrace\tools\timer();echo
'计算时间戳 : '
.$timer
->timeStamp('2018-04-24 15:48:04'
).'<br />'
;
计算日期与日期间的差值 DValue($timer1, $timer2)
参数:
Code phpLine:2复制1. 2.
1
、起始日期及时间,支持的格式 Y-m-d H:i:s 或 m/d/Y H:i:s2
、结束日期及时间,支持的格式 Y-m-d H:i:s 或 m/d/Y H:i:s
演示:
Code phpLine:2复制1. 2.
$timer
=new
phpGrace\tools\timer();echo
'计算时间差 : '
.$timer
->DValue('2018-04-25 15:48:18'
,'04/25/2018 15:48:12'
);
过去时间格式化 fromTime($time)
参数:时间戳
演示:
Code phpLine:7复制1. 2. 3. 4. 5. 6. 7.
- <?php
class
indexControllerextends
grace{public
function
index(){$timer
=new
phpGrace\tools\timer();echo
$timer
->fromTime($timer
->timeStamp(date
('Y-m-d'
).' 01:00:00'
));- }
- }
下载地址
mac 系统环境 可以在编辑器的tools目录下通过 Terminal 执行命令行直接下载到目录里
Code bashLine:1复制1.
- curl -O http://liukuaizhuan.gitee.io/phpgracemanual/工具/日期时间换算类/timer.php