diff options
| author | Eltrac Koalar <hi@guhub.cn> | 2022-09-29 23:23:39 +0800 |
|---|---|---|
| committer | Eltrac Koalar <hi@guhub.cn> | 2022-09-29 23:23:39 +0800 |
| commit | 4e6bba09dd1786422071c9c3e245c8d3df4c252b (patch) | |
| tree | d0789bd6acbff2c2d42c1501554b07d7b41b928f /libs | |
| parent | 890555ad3e10a04c99d97b7e157c7c2987309a6a (diff) | |
:gem: Add: 添加自定义时间格式设置
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/Matcha.php | 51 | ||||
| -rw-r--r-- | libs/Options.php | 8 |
2 files changed, 33 insertions, 26 deletions
diff --git a/libs/Matcha.php b/libs/Matcha.php index fc3a7a1..c3d76e9 100644 --- a/libs/Matcha.php +++ b/libs/Matcha.php @@ -235,29 +235,34 @@ class Matcha */ public static function date($created) { - //计算时间差 - $diff = time() - $created; - $d = floor($diff/3600/24); - - $Y = date('Y', $created); - - if(date('Y-m-d', $created)==date('Y-m-d')){ - return '今天'; - } - elseif($d==1){ - return '昨天'; - } - elseif($d==2){ - return '前天'; - } - elseif($d<=31){ - return $d.' 天前'; - } - elseif($Y==date('Y')) { - return date('m-d', $created); - } - else { - return date('Y-m-d', $created); + if(Helper::options()->timeFormat!=''){ + return date(Helper::options()->timeFormat, $created); + }else{ + //计算时间差 + $diff = time() - $created; + $d = floor($diff/3600/24); + + $Y = date('Y', $created); + + //输出时间 + if(date('Y-m-d', $created)==date('Y-m-d')){ + return '今天'; + } + elseif($d==1){ + return '昨天'; + } + elseif($d==2){ + return '前天'; + } + elseif($d<=31){ + return $d.' 天前'; + } + elseif($Y==date('Y')) { + return date('m-d', $created); + } + else { + return date('Y-m-d', $created); + } } } diff --git a/libs/Options.php b/libs/Options.php index 76419d3..39a6a43 100644 --- a/libs/Options.php +++ b/libs/Options.php @@ -129,9 +129,11 @@ function themeConfig($form) { <p class="description">使用特定的 JSON 格式书写,可以在首页文章目录之前展示一个相关链接版块,详情请查看说明文档</p><hr>')); $form->addInput($relatedLinks); - /** - * 自定义 - */ + //自定义时间显示 + $timeFormat = new Typecho_Widget_Helper_Form_Element_Text('timeFormat', NULL, NULL, _t('自定义时间格式'), _t(' + <p class="description">留空则默认采用人性化时间(即“昨天、前天、几天前”),若不想要使用人性化时间则在此填入 PHP 时间格式,例如:<code>Y-m-d G:i:s</code></p>')); + $form->addInput($timeFormat); + //自定义 head $customHead = new Typecho_Widget_Helper_Form_Element_Textarea('customHead', NULL, NULL, _t('自定义 head 头部信息'), _t(' <p class="description">将会输出在 head 标签结束之前,通常用于引入 css 文件。</p>')); |
