human_time_diff
apply_filters( ‘human_time_diff’, string $since , int $diff , int $from , int $to )
过滤器::过滤两个时间戳之间人类可读的差异。
Filter Hook: Filters the human readable difference between two timestamps.
参数(Parameters)
参数 | 类型 | 说明 |
---|---|---|
$since | (string) | 人类可读文本的差异。 |
$diff | (int) | 秒的差别。 |
$from | (int) | 差异开始的Unix时间戳。 |
$to | (int) | 结束时差的Unix时间戳。 |
源码(Source)
/** * Determines the difference between two timestamps. * * The difference is returned in a human readable format such as "1 hour", * "5 mins", "2 days". * * @since 1.5.0 * * @param int $from Unix timestamp from which the difference begins. * @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set. * @return string Human readable time difference. */ function human_time_diff( $from, $to = '' ) { if ( empty( $to ) ) { $to = time(); } $diff = (int) abs( $to - $from ); if ( $diff < hour_in_seconds="" )="" {="" $mins="round(" $diff="" minute_in_seconds="" );="" if="" (="" $mins=""><= 1="" )="" $mins="1;" translators:="" min="minute" */="" $since="sprintf(" _n(="" '%s="" min',="" '%s="" mins',="" $mins="" ),="" $mins="" );="" }="" elseif="" (="" $diff="">< day_in_seconds="" &&="" $diff="">= HOUR_IN_SECONDS ) { $hours = round( $diff / HOUR_IN_SECONDS ); if ( $hours <= 1="" )="" $hours="1;" $since="sprintf(" _n(="" '%s="" hour',="" '%s="" hours',="" $hours="" ),="" $hours="" );="" }="" elseif="" (="" $diff="">< week_in_seconds="" &&="" $diff="">= DAY_IN_SECONDS ) { $days = round( $diff / DAY_IN_SECONDS ); if ( $days <= 1="" )="" $days="1;" $since="sprintf(" _n(="" '%s="" day',="" '%s="" days',="" $days="" ),="" $days="" );="" }="" elseif="" (="" $diff="">< 30="" *="" day_in_seconds="" &&="" $diff="">= WEEK_IN_SECONDS ) { $weeks = round( $diff / WEEK_IN_SECONDS ); if ( $weeks <= 1="" )="" $weeks="1;" $since="sprintf(" _n(="" '%s="" week',="" '%s="" weeks',="" $weeks="" ),="" $weeks="" );="" }="" elseif="" (="" $diff="">< year_in_seconds="" &&="" $diff="">= 30 * DAY_IN_SECONDS ) { $months = round( $diff / ( 30 * DAY_IN_SECONDS ) ); if ( $months <= 1="" )="" $months="1;" $since="sprintf(" _n(="" '%s="" month',="" '%s="" months',="" $months="" ),="" $months="" );="" }="" elseif="" (="" $diff="">= YEAR_IN_SECONDS ) { $years = round( $diff / YEAR_IN_SECONDS ); if ( $years <= 1="" )="" $years="1;" $since="sprintf(" _n(="" '%s="" year',="" '%s="" years',="" $years="" ),="" $years="" );="" }="" *="" *="" filter="" the="" human="" readable="" difference="" between="" two="" timestamps.="" *="" *="" @since="" 4.0.0="" *="" *="" @param="" string="" $since="" the="" difference="" in="" human="" readable="" text.="" *="" @param="" int="" $diff="" the="" difference="" in="" seconds.="" *="" @param="" int="" $from="" unix="" timestamp="" from="" which="" the="" difference="" begins.="" *="" @param="" int="" $to="" unix="" timestamp="" to="" end="" the="" time="" difference.="" */="" return="" apply_filters(="" 'human_time_diff',="" $since,="" $diff,="" $from,="" $to="" );="" }="">
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
4.0.0 | wp-includes/formatting.php:3778 | 1 | 0 |
human_time_diff 为WP2原创文章,链接:https://www.wp2.cn/hook/human_time_diff-2/