我需要獲取不同時區中兩個日期時間之間的小時和分鐘差異。
我有MySQL中的日期時間,以及MySQL中位置的偏移量。
我曾嘗試:
<cfset departure = CreateDateTime(2017,01,27,21,00,00)> <!--- (this time zone is +2) --->
<cfset arrival = CreateDateTime(2017,01,28,06,40,00)> <!--- (this time zone is -5) --->
<cfset depart_timezone = 2>
<cfset arrive_timezone = -5>
<cfset difference = datediff("h",departure,arrival)><!--- get the difference in hours --->
<cfset timezonedif = depart_timezone - arrive_timezone><!--- get the difference between the time zones (answer should be 7)--->
<cfset duration = difference + timezonedif><!--- add the time zone difference to the flight difference --->
<cfoutput>
(Duration: #duration# hours)<br>
</cfoutput>
這返回16小時,這是不正確的。差異應該是15小時40分鐘。幫助將不勝感激。在這裏呆了幾個小時。
這是正確的。您提供的這些時間之間的差異是9小時。 datediff不會給你分鐘時,你使用'h',因爲它只檢查小時。如果你想允許時區,那麼你將需要計算實際時間,然後獲得差異。它不能猜測這些是不同的區域。一開始將dateAdd()時區的時間,然後傳遞它。或者DateConvert()來傳遞並傳遞它。 – haxtbh
更新我的問題,並嘗試了DateAdd,但仍然沒有得到正確的結果。 –
我在上次評論中提到了爲什麼會議記錄沒有返回。使用'h'只會返回上下小時數。所以16是正確的。您將需要使用幾分鐘或幾秒鐘來比較差異,並計算出總共需要多少小時和幾分鐘。標準的分鐘到小時轉換。 – haxtbh