常用函数-human_time_diff()

4条评论

说明

判断两个时间标记的差异。

以人类可阅读的格式,如“1小时”、“5分钟”、“两天”,返回时间标记的差异。

用法

<?php human_time_diff( $from, $to ) ?>

参数

$from

(整数)(必需)开始有差别的Unix时间标记

默认值:None

$to

(整数)(可选)差别结束时的Unix时间标记。如果未设置默认值,默认值会变为time()

默认值:''

返回的值

(字符串)

人类可读的时间差异

示例

要打印出某个输入项的时间("2 days ago"):

<?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?>

评论时间:

<?php echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago'; ?>

注释

函数历史

始见于1.5.0版本

源文件

human_time_diff()位于 wp-includes/formatting.php中。

#1
我这调用那个评论的相对时间后,全都都是清一色的显示“15016 天 ago”哦,怎么回事啊?
#2
清一色的显示“15016 天 ago,应该是由于该函数调用你购买空间上的时间,没有进行有效的时间格式转换造成的。
#3
请教怎么样转换啊?
#4
这个现在很常用

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自动断行和分段。

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.