pear/date_humandiff

生成人类易于理解的时间差。

v0.5.0 2014-03-23 12:03 UTC

This package is not auto-updated.

Last update: 2024-09-18 18:22:58 UTC


README

生成人类易于理解的时间差。

该类支持分钟、小时、天、周、月和年。

示例

  • 5秒前 -> 刚才
  • 65秒前 -> 一分钟前
  • 120秒前 -> 两分钟前
  • 一周前
  • 三周前
  • 一个月前
  • 八个月前
  • 一年前
  • 五年前

用法

<?php
require_once 'Date/HumanDiff.php';
$dh = new Date_HumanDiff();
echo $dh->get(time() - 3600);//shows "an hour ago"
echo $dh->get(time() + 3600 * 24, time()); //shows "tomorrow"

?>

支持的语言

  • 德语
  • 英语
  • 希腊语
  • 波斯语
  • 俄语

使用 setLocale() 设置语言

$dh = new Date_HumanDiff();
$dh->setLocale('de');
echo $dh->get(time() - 60 * 5) . "\n"; //shows "vor 5 Minuten"

其他库

https://github.com/azer/relative-date/blob/master/lib/relative-date.js
JavaScript; 作为 Date_HumanDiff 基础的库
https://github.com/rmm5t/jquery-timeago
JavaScript; 具有本地化选项
http://pypi.python.org/pypi/py-pretty
Python