gufy/date-interval

用于计算日期间隔并转换为可读间隔的类

v1.0.1 2013-11-28 05:27 UTC

This package is auto-updated.

Last update: 2024-09-13 17:56:33 UTC


README

{
	"require":{
		...
		"gufy/date-interval":"dev-master"
		...
	}
}

用法

让我们享受编程乐趣。以下是示例代码

<?php
// add this if you are using composer
require 'vendor/autoload.php';

$interval = 14400; // note that the interval is in miliseconds
$class = new \Gufy\DateInterval($interval);

// or you can manually set the interval using this
$class->setInterval($interval);

// get the seconds 
$class->getSeconds();

// if you want the output is in integer, you could use PHP_ROUND_HALF_UP or PHP_ROUND_HALF_DOWN constant while calling it

$class->getSeconds(PHP_ROUND_HALF_DOWN); 

// get the minutes
$class->getMinutes();

// get the hours 
$class->getHours();

// if you want format it just use this thing
$format = "{hours} hours {minutes} minutes {seconds} seconds";
$class->format($format);

// above will print out every thing, even hours or minutes or seconds is zero (0).
// if you want to ignore that, you can do this thing

$format = array(
	'template'=>'{hours} {minutes} {seconds}',
	'{hours}'=>'{hours} hours',
	'{minutes}'=>'{minutes} minutes',
	'{seconds}'=>'{seconds} seconds'
);
$class->format($format);

下一个功能

- Add date capability, currently only time that can cover by this class
- Add more lexer on format

支持

如果您发现任何错误或混乱,可以通过在仓库中提交问题或通过电子邮件发送给我 mgufronefendi@gmail.com 来报告。贡献是受欢迎的。首先将此仓库分叉并使其满足您的需求,然后向此仓库发送拉取请求。

谢谢