簡體   English   中英

php的imap_fetch_overview()日期字段格式為MySQL時間戳

[英]php's imap_fetch_overview() date field format as MySQL timestamp

php的imap_fetch_overview()日期鍵是這樣的日期格式:

Thu, 22 Aug 2013 07:53:32 -0400

kes。 是否可以自定義日期格式? 我在文檔中沒有看到任何內容,因此我認為沒有。 我需要做的是將其轉換為MySQL的時間戳格式。

如果不重寫和重新編譯源代碼,就無法自定義包含的PHP函數/庫。 可以自定義,繼承或調整類。 但是在這種情況下,您可以做的是簡單的日期/時間的strtotime() 然后將其轉換為MySQL datetime。

$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也將到達日期作為Unix時間戳記帶回udate對象。

也請在此處引用對象數組: http : //php.net/manual/zh/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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM