hashbang / epoctools
提供各种epoc处理函数的库
v1.1.3
2014-05-12 03:52 UTC
Requires
- php: >=5.0.0
This package is not auto-updated.
Last update: 2024-09-28 14:58:27 UTC
README
这是一个简单的库,提供各种epoc处理功能。
安装
安装到CodeIgniter中
下载此存储库并将其复制到您的应用程序目录中。
或者,使用 Composer 进行安装。
函数
age
- humanize
的辅助函数,返回某物的年龄
此函数用于计算一个物品相对于另一个时间的年龄。参见 humanize
获取完整示例列表
$this->EpocTools = new EpocTools();
$this->EpocTools->Age(strtotime('2011-01-01'), strtotime('2011-01-02')) // Reutns '1 day'
$this->EpocTools->Age(strtotime('2011-01-01 22:00'), strtotime('2011-01-02 23:00')) // Reutns '1 day, 1 hour'
date
- 返回epoc的中午时间
当给出任何epoc风格的日期时,此函数将该epoc的时间设置为午夜。
$this->EpocTools = new EpocTools();
$this->EpocTools->date(time()); // Returns the epoc at midnight today
$this->EpocTools->date(strtotime('2011-01-01 04:32:21')); // Returns midnight on 01/01/2011
epocdateend
- 返回给定epoc日期的最后秒
与 epocdate
相比,此函数返回给定日期的最后可能的秒。
$this->EpocTools = new EpocTools();
$this->EpocTools->dateend(time()); // Returns the last possible second of todays date
$this->EpocTools->dateend(strtotime('2011-01-01 04:32:21')); // Returns 23:59:59 on 01/01/2011
getstamp
- date()
的逆函数
此函数接收一个给定的字符串,并使用提供的模板将其转换为日期。这与默认的PHP Date()函数相反。
$this->EpocTools = new EpocTools();
$this->EpocTools->getstamp('d/m/Y H:M','02/07/1983 1035'); // Returns unix timestamp 425952900
humanize
- 以人类格式返回一系列秒
此函数可用于返回事件相对于当前时间的过去或未来的距离
$this->EpocTools = new EpocTools();
$this->EpocTools->Humanize(time() - 60); // Returns '60 seconds ago'
$this->EpocTools->Humanize(time() - 5400); // Returns '1 hour, 30 minutes ago'
$this->EpocTools->Humanize(time() - 72576000); // Returns '2 weeks ago'
可以指定各种选项,包括应该选择多少时间尺度(即有多具体),例如 '2 weeks, 1 hour' 将有两个块,'2 weeks, 1 hour, 38 minutes, 42 seconds' 将有四个。
shorthand
- 从人类可读的时间缩写中返回秒数
此函数返回从缩写时间字符串中确定的秒数。
$this->EpocTools = new EpocTools();
$this->EpocTools->Shorthand('1h') // Returns 3600 (1 hour - 60*60)
$this->EpocTools->Shorthand('1h30m') // Returns 5400 (1 hour 30 minutes - 60*60 + 30*60)
$this->EpocTools->Shorthand('2w') // Returns 72576000 (2 weeks - 7*24*60*60*60*2)