2014-02-18 31 views
1

我有從Web日曆ICS文件中解析的ISO DATETIME格式。我在谷歌和雅虎創建了日曆事件。在google中,我創建了11:00至11:30的IST時間。 在雅虎,我創建了11:30至11:45 IST的時間。PHP中的ISO日期時間

我收到了兩個事件的ICS文件。我的問題是ICS文件中的事件開始時間和結束時間。

谷歌開始時間 - 20140218T060000Z(提供GMT時間)

雅虎開始時間 - 20140218T113000Z(提供本地時間)

我如何檢查是否在ISO日期時間的時區是GMT,並將其轉換爲GMT如果不?請幫我實現這一點。提前致謝。

+0

這是不可能的說,因爲機器人h時區根據其字符串表示形式爲Z(ulu)aka GMT。 –

+0

@Jack SO提到這些日期已經被解析。 – oberron

回答

1

應該有可以使用的iCal文件時區聲明。

The RFC地方本就DTSTART,例如:

DTSTART;TZID=America/New_York:19980119T020000 

但iCal的是不是一個非常精確的「科學」,好像每個人都使用它的不同。我看過這樣的時區聲明:

X-WR-TIMEZONE:Europe/Berlin 

它只在ical文件中顯示一次。

創建DateTime對象後,可以使用DateTime :: setTimezone進行設置。從PHP documentation例如:

$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru')); 
echo $date->format('Y-m-d H:i:sP') . "\n"; 

$date->setTimezone(new DateTimeZone('Pacific/Chatham')); 
echo $date->format('Y-m-d H:i:sP') . "\n"; 
-1

您可以在php中使用datestrtotime函數。

// apply this to all your times 
    $start_time = "20140218T060000Z"; 
    $timeZone = date("e",strtotime($start_time)); 

    if($timeZone != "UTC"){ // UTC is same as GMT in case you're wondering 
     $start_time_gmt = gmdate("Ymd\THis\Z",$start_time); // the \T an \Z are key characters for the date function so you need to escape them if you want to display it in that format 
    } 

參考文獻: http://www.php.net/manual/en/function.date.php

http://php.net/strtotime

0

作爲傑拉德指示差異來自這一事實DTSTART(和方式也DTEND)的事件的屬性經由X-WR-TIMEZONE任一引用明確地(如每RFC 5545 - time zone identifier)或隱含(Apple iCal)。

在你必須處理VTIMEZONE部件的第一種情況(RFC5545 - VTIMEZONE component)。對於您將需要一個ICalendar parser in PHP that supports timezones

在第二種情況下,必須參考Olson database,並且可能需要使用timezonedb代替默認的PHP之一。

但是你應該閱讀J. Dunnell對這個旅程入門之前X-WR-TIMEZONE處理的可能的陷阱這個blog入門...