簡體   English   中英

如何從php中的舊時間字符串中查找區域的當前時間?

[英]How to find current time of a region from a old time string in php?

我從某些郵件date標題中獲取時間字符串。 我需要獲得多少秒才能將郵件發送給用戶。

這是我要解決的代碼。

<?php
//time string found in mail date header
$time_string = 'Wed, 15 Nov 2017 14:50:53 -0800 (PST)';

//when i use 'D, j M Y G:i:s O (e)' as identifier then date_create_from_format returns false
$mail_date = explode(" ", $time_string);
unset($mail_date[6]);
$dt_in = date_create_from_format('D, j M Y G:i:s O', implode(" ", $mail_date));
$time_in = strtotime(date_format($dt_in, 'd-m-Y H:i:s')) ; // This time may be according to my time zone (that is wrong need according to that time zone '-0800')

//returns time zone that is not compatible with php
$time_zone = date_format($dt_in, 'T'); //returns GMT-0800

//rest of the code not working
date_default_timezone_set($time_zone); //date_default_timezone_set(): Timezone ID 'GMT-0800' is invalid
$difference = time()-$time_in;
print_r($difference);
?>

糾正此代碼或像這樣進行操作並非沒有問題。 我需要得到時差。 任何解決方案都是可取的。 提前致謝。

將日期從電子郵件轉換為時間戳並與當前時間戳進行比較:

$time_string = 'Wed, 15 Nov 2017 14:50:53 -0800 (PST)';
$mail_date = explode(" ", $time_string);
unset($mail_date[6]);
$mail_datetime = date_create_from_format('D, j M Y G:i:s O', implode(" ", $mail_date));
$time_diff_in_seconds = time() - $mail_datetime->getTimestamp();

暫無
暫無

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

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