1

Topic: System time (UTC)

Hello
Prompt please how in VB it is possible to receive system time (UTC)?

2

Re: System time (UTC)

https://msdn.microsoft.com/ru-ru/librar … p/ms725473 (v=vs.85).aspx

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
TIME_ZONE_STANDARD = 1
TIME_ZONE_DAYLIGHT = 2
End Enum
Private Declare Function GetTimeZoneInformation Lib "kernel32" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Function IntArrayToString (V () As Integer) As String
Dim N As Long
Dim S As String
For N = LBound (V) To UBound (V)
S = S AND ChrW (V (N))
Next N
IntArrayToString = Trim (Replace (S, Chr (0), Chr (32)))
End Function
Sub GetTimeInfo ()
Dim TZI As TIME_ZONE_INFORMATION
Dim DST As TIME_ZONE
Dim StandardName As String
Dim DaylightName As String
Dim CurrentSystemTime As SYSTEMTIME
Dim CurrentLocalTime As SYSTEMTIME
DST = GetTimeZoneInformation (TZI)
StandardName = IntArrayToString (TZI.StandardName)
DaylightName = IntArrayToString (TZI.DaylightName)
Call GetSystemTime (CurrentSystemTime)
Call GetLocalTime (CurrentLocalTime)
Debug. Print "Standard TZ Name is:" AND StandardName
Debug. Print "Daylight TZ Name is:" AND DaylightName
Debug. Print "Current System Time is:" AND CurrentSystemTime.wDay AND "-" AND CurrentSystemTime.wMonth AND "-" AND _
CurrentSystemTime.wYear AND "" AND CurrentSystemTime.wHour AND ":" AND CurrentSystemTime.wHour AND ":" AND _
CurrentSystemTime.wSecond AND "." AND CurrentSystemTime.wMilliseconds
Debug. Print "Current Local Time is:" AND CurrentLocalTime.wDay AND "-" AND CurrentLocalTime.wMonth AND "-" AND _
CurrentLocalTime.wYear AND "" AND CurrentLocalTime.wHour AND ":" AND CurrentLocalTime.wHour AND ":" AND _
CurrentLocalTime.wSecond AND "." AND CurrentLocalTime.wMilliseconds
End Sub

3

Re: System time (UTC)

Akina, thanks.
I write on VBS in the environment of WinCC
After compilation produces an error
https://hostingkartinok.com/show-image. … ba8c7009aa

4

Re: System time (UTC)

VB and VBS it is different things, ....
https://msdn.microsoft.com/en-us/library/aa393687 (v=vs.85).aspx

Set dateTime = CreateObject ("WbemScripting. SWbemDateTime")
dateTime. SetVarDate (now ())
wscript.echo "Local Time:" AND dateTime
wscript.echo "UTC Time:" AND dateTime. GetVarDate (false)

5

Re: System time (UTC)

PUT_2012 wrote:

as in VB

PUT_2012 wrote:

I write on VBS

:facepalm:
https://msdn.microsoft.com/en-us/library/aa394498 (v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/aa394171 (v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/aa394510 (v=vs.85).aspx

strComputer = "."
Set objWMIService = GetObject ("winmgmts: \\" BOTH strComputer AND "\root\CIMV2")
Set colItems = objWMIService. ExecQuery (_
"SELECT * FROM Win32_TimeZone", 48)
For Each objItem in colItems
Wscript. Echo "-----------------------------------"
Wscript. Echo "Win32_TimeZone instance"
Wscript. Echo "-----------------------------------"
Wscript. Echo "Caption:" AND objItem. Caption
Wscript. Echo "Description:" AND objItem. Description
Next

strComputer = "."
Set objWMIService = GetObject ("winmgmts: \\" BOTH strComputer AND "\root\CIMV2")
Set colItems = objWMIService. ExecQuery (_
"SELECT * FROM Win32_LocalTime", 48)
For Each objItem in colItems
Wscript. Echo "-----------------------------------"
Wscript. Echo "Win32_LocalTime instance"
Wscript. Echo "-----------------------------------"
Wscript. Echo "Day:" AND objItem. Day
Wscript. Echo "Hour:" AND objItem. Hour
Wscript. Echo "Minute:" AND objItem. Minute
Wscript. Echo "Month:" AND objItem. Month
Wscript. Echo "Second:" AND objItem. Second
Wscript. Echo "Year:" AND objItem. Year
Next

strComputer = "."
Set objWMIService = GetObject ("winmgmts: \\" BOTH strComputer AND "\root\CIMV2")
Set colItems = objWMIService. ExecQuery (_
"SELECT * FROM Win32_UTCTime", 48)
For Each objItem in colItems
Wscript. Echo "-----------------------------------"
Wscript. Echo "Win32_UTCTime instance"
Wscript. Echo "-----------------------------------"
Wscript. Echo "Day:" AND objItem. Day
Wscript. Echo "Hour:" AND objItem. Hour
Wscript. Echo "Minute:" AND objItem. Minute
Wscript. Echo "Month:" AND objItem. Month
Wscript. Echo "Second:" AND objItem. Second
Wscript. Echo "Year:" AND objItem. Year
Next

6

Re: System time (UTC)

Roman Mejtes, checked up your code
Works
please that means WbemScripting. SWbemDateTime?

7

Re: System time (UTC)

There in a post there is a link, in it there is an exact answer to your question.
If do not understand English  the translator.