我正在尝试找到一种方法来计算我的时区(中部)和(太平洋;山区;东部)之间的天数。只是不知道从哪里开始。我的标准如下:
单元格 C5:C100 将是以下格式的时间戳:2010 年 3 月 18 日 23:45,但日期和时间不同。单元格 D5:D100 将是文本形式的相应时区:太平洋;山; 东; 中央。
单元格 F5 将是需要以天为单位的持续时间。
只是不知道如何编写公式来给我我想要的东西。感谢您提前提供任何帮助。谢谢
VBA 和 VB6 都没有提供用于处理时区、格林威治标准时间 (GMT,也称为 UTC) 或夏令时的任何本机函数。要使用这些值,您必须使用一些 Windows 应用程序编程接口 (API) 函数。本页介绍了这些 API 函数以及如何在 VBA 代码中使用它们。
The simplest way is probably a nested IF formula:
=IF(D22="Pacific",(1/24*2),IF(D22="Mountain",(1/24),IF(D22="Eastern",-(1/24),0)))
Or using the LOOKUP
function to return the same:
=(C5+(1/24*LOOKUP(D5,{"Central","Eastern","Mountain","Pacific"},{-2,-3,-1,0})))-C5
Alternatively, you could create a UDF that takes the local date/time and works out the Pacific date/time from the textual representation of the timezone:
Function TimeDifference(LocalTime As Range, TimeZone As Range) As Date
Application.Volatile
Dim TimeOffset As Long
Select Case TimeZone
Case "Mountain"
TimeOffset = -1
Case "Central"
TimeOffset = -2
Case "Eastern"
TimeOffset = -3
Case Else
TimeOffset = 0
End Select
TimeDifference = (1 / 24 * TimeOffset)
End Function
You would call this from column F like this:
=TIMEDIFFERENCE(C5,D5)