В PowerShell я могу использовать windows системные API
$estzone = [System.TimeZoneInfo]::FindSystemTimeZoneById("Eastern Standard Time")
$esttime = [System.TimeZoneInfo]::ConvertTimeFromUtc($test2, $estzone)
"GMT= " +$test2 + " EST =" + $esttime
Я не могу сослаться на FindSystemTimeZoneById или ConvertTimeFromUt c в VB
Я пытался
Option Explicit
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(0 To 31) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(0 To 31) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private Enum TIME_ZONE
TIME_ZONE_ID_INVALID = 0 ' Cannot determine DST
TIME_ZONE_STANDARD = 1 ' Standard Time, not Daylight
TIME_ZONE_DAYLIGHT = 2 ' Daylight Time, not Standard
End Enum
Private Declare PtrSafe Function FindSystemTimeZoneById Lib "kernel32" (lpTimeZone As String) As TIME_ZONE_INFORMATION
Private Declare PtrSafe Function ConvertTimeFromUtc Lib "kernel32" (lpSystemTime As Date, pTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Function GetLocalTimeFromGMTerc(GMTTime As Date)
Dim estzone As TIME_ZONE_INFORMATION
Dim esttime As Date
estzone = FindSystemTimeZoneById("Eastern Standard Time")
esttime = ConvertTimeFromUtc(GMTTime, estzone)
GetLocalTimeFromGMTerc = esttime
End Function
Кажется, что это компилируется / запускается, но выдает «Значение, используемое в формуле, имеет неправильный тип данных». Я предполагаю, что делаю это совершенно неправильно. Любая помощь?
Спасибо!