php的imap_fetch_overview()日期键是这样的日期格式:
Thu, 22 Aug 2013 07:53:32 -0400
哎呀。是否可以自定义日期格式?我没有在文件中看到任何东西,所以我认为没有。我需要做的是将其转换为MySQL的时间戳格式。
如果不重写和重新编译源代码,就无法自定义包含的PHP函数/库。类可以是自定义的,也可以是继承和调整的。但在这种情况下,您可以做的是一个简单的日期/时间的strtotime()
。然后将其转换为MySQL日期时间。
$array=imap_fetch_overview();
$unixTimestamp=strtotime($array['date']);
echo date("Y-m-d H:i:s", $unixTimestamp);
您可以使用strtotime函数。此函数返回unix时间戳
<?php
$timestamp=strtotime("Thu, 22 Aug 2013 07:53:32 -0400");
?>
您可以使用日期功能创建新的日期时间格式:
<?php
echo date("d/m/Y H:i:s", strtotime("Thu, 22 Aug 2013 07:53:32 -0400"));
?>
更多信息:
http://www.php.net/strtotime
http://www.php.net/date
除了strtotime()
函数,我们还可以使用PHP中提供的DateTime
类。只需将imap_fetch_overview()返回的日期字符串放入DateTime
构造函数即可。示例如下:
<?php
$result=imap_fetch_overview($mbox_stream,$emailnumber);
$message_date=new DateTime($result[0]->date);//Put date result at DateTime constructor
echo $message_date->format("Y-m-d H:i:s");//Formating the DateTime value to MySQL DATETIME format
?>
PHP-imap_fetch_overview还将到达日期作为udate对象中的Unix时间戳带回。
另请参阅此处的对象数组:http://php.net/manual/en/function.imap-fetch-overview.php
结果数组中可用对象的列表:
subject - the messages subject
from - who sent it
to - recipient
date - when was it sent
message_id - Message-ID
references - is a reference to this message id
in_reply_to - is a reply to this message id
size - size in bytes
uid - UID the message has in the mailbox
msgno - message sequence number in the mailbox
recent - this message is flagged as recent
flagged - this message is flagged
answered - this message is flagged as answered
deleted - this message is flagged for deletion
seen - this message is flagged as already read
draft - this message is flagged as being a draft
udate - the UNIX timestamp of the arrival date