Public 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 Public Type TIME_ZONE_INFORMATION Bias As Long StandardName(0 To 31) As Integer StandardDate As SYSTEMTIME StandardBias As Long DaylightName(0 To 31) As String * 64 DaylightDate As SYSTEMTIME DaylightBias As Long End Type Private Declare Function SetTimeZoneInformation Lib "Kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long Private Declare Function GetTimeZoneInformation Lib "Kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long Private Declare Function TzSpecificLocalTimeToSystemTime Lib "Kernel32" (ByRef TimeZoneInfo As TIME_ZONE_INFORMATION, ByRef Local_Time As SYSTEMTIME, ByRef UTC_Time As SYSTEMTIME) As Long Public Function ConvertLocalTimeToUtcTime(ByVal LocalDateTime As Date) As Date ' L'heure fournie est exprimée en heure locale et au format du système ' L'heure renvoyée sera exprimée en UTC, et toujours au format du système ' Accepte n'importe quel format de date du moment que ce format est le format de l'OS Dim tzi As TIME_ZONE_INFORMATION Dim UtcTime As SYSTEMTIME Dim LocalTime As SYSTEMTIME Call GetTimeZoneInformation(tzi) With LocalTime .wDay = Day(LocalDateTime) .wMonth = Month(LocalDateTime) .wYear = Year(LocalDateTime) .wHour = Hour(LocalDateTime) .wMinute = Minute(LocalDateTime) .wSecond = Second(LocalDateTime) End With Call TzSpecificLocalTimeToSystemTime(tzi, LocalTime, UtcTime) With UtcTime ConvertLocalTimeToUtcTime = CDate(DateSerial(.wYear, .wMonth, .wDay) & _ " " & _ TimeSerial(.wHour, .wMinute, .wSecond)) End With End Function Sub Bouton3() Dim UtcDateTime As Date Dim TempsLocal As Date TempsLocal = Format(Feuil1.DTPicker1.Value, "dd/mm/yyyy hh:mm") 'date UTC' UtcDateTime = ConvertLocalTimeToUtcTime(TempsLocal) 'Date locale' End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Type TIME_ZONE_INFORMATION Bias As Long StandardName As String * 64 StandardDate As SYSTEMTIME StandardBias As Long DaylightName As String * 64 DaylightDate As SYSTEMTIME DaylightBias As Long End Type Private Type TIME_ZONE_INFORMATION Bias As Long StandardName(32) As Integer StandardDate As SYSTEMTIME StandardBias As Long DaylightName(32) As Integer DaylightDate As SYSTEMTIME DaylightBias As Long End Type