簡體   English   中英

DATETIME 到 PHP 中的實時

[英]DATETIME to real time in PHP

從 Wordpress 帖子(存儲在 DATETIME 中的 post_date_gmt 字段)獲取時間,我如何將該信息(例如 2011-03-23 20:28:26)轉換為 PHP 中的實際可調整日期? (如 2011 年 3 月 23 日星期四)

echo date('r', strtotime($datetime));

echo date('r', strtotime('2011-03-23 20:28:26'));

echo date('l, F jS, Y', strtotime('2011-03-23 20:28:26'));

有關更多格式選項,請參見date()

您可以使用strtotimeDateTime class。

// Using strtotime
$date = strtotime($row['post_date_gmt']);

// Using the DateTime class
$date = new DateTime($row['post_date_gmt']);

因為日期是格林威治標准時間,而您的服務器很可能不是,所以指定時區也是明智之舉。 這是一個使用DateTimeZone的示例。

$timezone = new DateTimeZone('UTC');
$date = new DateTime($row['post_date_gmt'], $timezone);

利用

date(formatString, yourDate) 

或者

gmdate(formatString, yourDate) 

格式字符串示例:'D, d MYH:i:s T'

暫無
暫無

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

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