上次编辑条目的UNIX时间戳


UNIX timestamp of the last time an entry was edited

在表达式引擎中,{edit_date}标记不会像{entry_date}那样返回UNIX时间戳。为了解决这个问题,我使用了下面的方法。

有人知道如何让这件事变得更容易吗?

{exp:channel:entries channel="pieces" limit="1" track_views="three"}
<?php
$edit_date_string = {edit_date};
$edit_date = NULL;
if(!isset($edit_date_string)) {
  $edit_date = {entry_date};
} else {
  // Date format: 2011 05 25 00:53:44
  // Raw: 20110525005344
  $hour   = substr($edit_date_string, -6, 2);
  $minute = substr($edit_date_string, -4, 2);
  $second = substr($edit_date_string, -2, 2);
  $day    = substr($edit_date_string, -8, 2);
  $month  = substr($edit_date_string, -10, 2);
  $year   = substr($edit_date_string, -12, 2);
  $edit_date = mktime($hour, $minute, $second, $month, $day, $year);
}
echo $edit_date;
?>
{/exp:channel:entries}

顺便说一句,这似乎是一种不一致性,使处理和比较日期变得更加困难。这可能有一个很好的理由。有人知道吗?感谢

如果你有PHP 5.3,那么有DateTime::createFromFormat:

$edit_date = DateTime::createFromFormat('YmdHis', $edit_date_string)->getTimestamp();

或者,更直接地说,根据表达式引擎文档:

$edit_date = {edit_date format="%U"}