2017-05-04 56 views

回答

0

如果您想为事件使用自定义时间戳并知道如何编写基本的PHP代码,您可以使用php的DateTime::diff方法或更好的方法,使用Carbon来获取您的自定义时间戳和当前日期之间的差异。

链接文档中的示例应该足以理解并回显日期之间的差异。现在,在WordPress内部使用该代码,将该代码写入主题的functions.php文件中的一个函数中,并将该值返回create a shortcode以获得差异。

function eventdiff_func($atts) { 

    // write code which calculates the difference here and store it in $diff 

    return $diff; 
} 
add_shortcode('event_diff', 'eventdiff_func'); 

现在你可以使用简码[event_diff]等。无论您想输出你计算出的差异。

0

您可以使用human_time_diff功能区别是以可读的格式返回。你可以阅读更多关于human_time_diffclick here

相关问题