我有一个邮件要发送提醒,说明客户上次登录日期。我的时间保存在 unixtimestamp 中。因此,当我从数据库中获取并将其包含在电子邮件中时,它会在日期前 6 天给我。我在这里做错了什么?
部分数据:
$lastlogin = mysql_result($result,$i,"lastlogin");
$newlastlogin = date("d-m-Y", $lastlogin);
电子邮件正文:
$msg .= "Your Last Activity: $newlastlogin.<BR>";
上次从MySQL登录的日期为27-05-2012
但是当邮件发出时,它会显示 21-05-2012
顺便说一句,我尝试了
$newlastlogin = date("d-m-Y", strtotime($lastlogin));
任何帮助和建议将不胜感激
您可以使用以下方法直接从数据库将日期转换为 Unix 时间戳unix_timestamp(日期(在您的选择语句上。
示例:(假设登录名表上有一个名为 last_login 的字段(
$sql = "SELECT UNIX_TIMESTAMP(last_login) as lastlogin from logins";
详情请见此处:http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_unix-timestamp