0

我正在尝试在我的浏览器上显示 mysql 存储的 unix 时间戳值(并将它们保存到 CSV 文件中)。这些值存储为 int (11)。问题是,当我显示它们时,我看到了“d”、“P”、“j”、“M”和其他用于格式化日期的字符,而不是实际的时间戳。怎么了?

<?php

/* MySQL connection and database connection code */
mysql_query ("SELECT emailaddress, subscribedate FROM email_list_subscribers WHERE subscriberid = '$sid'");

$email_result= mysql_query ("SELECT emailaddress, subscribedate FROM  email_list_subscribers WHERE subscriberid = '$sid'");
if (mysql_num_rows ($email_result) == 0) {
  $email = '';
  $subscribedate = '';
} else {
  $email = mysql_fetch_assoc ($email_result);
  $email =  $email['emailaddress'];
  $subscribedate = (string) ( $email['subscribedate']);
  echo $sid . " : " . $subscribedate . "<br/>";
}

?>
4

1 回答 1

1

您必须将时间戳值转换为日期时间才能显示格式化信息:

    $timestamp = '1348617600';

    $datetime = date("Y-m-d H:i:s", $timestamp);

    echo $datetime;

你也可以使用:

echo strtotime($timestamp);

小心,你必须考虑到时区

于 2012-09-26T19:52:25.773 回答