alexgx/yii-timeago

该包最新版本(dev-master)没有可用的许可信息。

该包的规范存储库似乎已丢失,因此该包已被冻结。

dev-master 2014-10-29 22:26 UTC

This package is not auto-updated.

Last update: 2024-05-07 05:18:49 UTC


README

yii框架的时间ago格式化工具

#安装 将yii-timeago复制到您的应用扩展文件夹。
在config main中添加到components部分

<?php
...
'components' => array(
	'format'=>array(
		'class'=>'application.extensions.timeago.TimeagoFormatter',
    ),
...
?>

#示例

<?php
// with timestamp
echo Yii::app()->format->timeago(time() - 60 * 5); // 5 minutes ago

// with DateTime object 
echo Yii::app()->format->timeago(new DateTime('2018-07-08 11:14:15'));

// with date formatted string
echo Yii::app()->format->timeago('2012-07-31 19:08:58');

// in CGridView column
...
'columns' => array(
	array(  'name'=>'create_date',
            'sortable' => true,
            'header'=>'Date',
            'type' => 'timeago',
    ),
...

// force locale in main config
...
'format' => array(
				'class'=>'application.modules.timeago.TimeagoFormatter',
            	'locale'=>'en_short',
        	),
...
?>

#支持的区域设置

  • en (英语), en_short (缩写英语)
  • da (丹麦) @lauer
  • de (德语)
  • fr (法语)
  • ja (日语)
  • ru (俄语)
  • uk (乌克兰语)
  • et (爱沙尼亚语) @kullar84
  • zn_cn (简体中文), zn_tw (繁体中文)
  • es (西班牙语) @yepes
  • ro (罗马尼亚语) @totpero

将来将添加更多区域设置。

#要求

  • PHP 5.3
  • Yii 1.1.x (已测试1.1.10及以上版本)