Connecting Tech Pros Worldwide Forums | Help | Site Map

vb6 UTC time?

jhLewis
Guest
 
Posts: n/a
#1: Aug 17 '05
Using vb6, I would like to have either a text box or label display the
current time in UTC format...I can't seem to find any instructions or code
snippets on how to accomplish it...

Any help appreciated...thanks.

John



Magnus McElroy
Guest
 
Posts: n/a
#2: Aug 17 '05

re: vb6 UTC time?




jhLewis wrote:[color=blue]
> Using vb6, I would like to have either a text box or label display the
> current time in UTC format...I can't seem to find any instructions or code
> snippets on how to accomplish it...
>
> Any help appreciated...thanks.
>
> John[/color]


I used this code. I cut-and-pasted it, so help yourself.

'After this point, I cut and pasted code from a Visual Basic group to
'try and help with the timezone problem.
Const TIME_ZONE_ID_INVALID = &HFFFFFFFF
Const TIME_ZONE_ID_UNKNOWN = &H0
Const TIME_ZONE_ID_STANDARD = &H1
Const TIME_ZONE_ID_DAYLIGHT = &H2

Type TIME_ZONE_INFORMATION
Bias As Long
StandardName As String * 32
StandardDate As Long
StandardBias As Long
DaylightName As String * 32
DaylightDate As Long
DaylightBias As Long
End Type

Declare Function GetTimeZoneInformation Lib "kernel32" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Function NowPlusTZBias() As Date

Dim usrTZI As TIME_ZONE_INFORMATION
Dim lngRetVal As Long

lngRetVal = GetTimeZoneInformation(usrTZI)
NowPlusTZBias = Now + (usrTZI.Bias / 1440)
End Function

To use it in the program, do this:

'If this is true, we're using Windows Time. Note that we have to
'compenstate for the timezone and use UTC. The NowPlusTZ Biaswas
'code taken from a MS access? newsgroup.
data_out(1) = CByte(Year(NowPlusTZBias) - 2000)
data_out(2) = CByte(Month(NowPlusTZBias))
data_out(3) = CByte(Day(NowPlusTZBias))
data_out(4) = CByte(Hour(NowPlusTZBias))
data_out(5) = CByte(Minute(NowPlusTZBias))
data_out(6) = CByte(Second(NowPlusTZBias))


In other words, copy the first part into your code (as I did) and
instead of using Now, use NowPlusTZBias

--
Magnus McElroy
Electrical Engineer (EIT)
HABIT Research
(250) 381-9425
Keith R. Weimer
Guest
 
Posts: n/a
#3: Aug 19 '05

re: vb6 UTC time?



"Magnus McElroy" <"[myfirstname]"@habitresearch.[com]> wrote in message
news:NyMMe.34735$vj.3766@pd7tw1no...[color=blue]
>
>
> jhLewis wrote:[color=green]
>> Using vb6, I would like to have either a text box or label display the
>> current time in UTC format...I can't seem to find any instructions or
>> code snippets on how to accomplish it...
>>
>> Any help appreciated...thanks.
>>
>> John[/color]
>
>
> I used this code. I cut-and-pasted it, so help yourself.
>
> 'After this point, I cut and pasted code from a Visual Basic group to 'try
> and help with the timezone problem.
> Const TIME_ZONE_ID_INVALID = &HFFFFFFFF
> Const TIME_ZONE_ID_UNKNOWN = &H0
> Const TIME_ZONE_ID_STANDARD = &H1
> Const TIME_ZONE_ID_DAYLIGHT = &H2
>
> Type TIME_ZONE_INFORMATION
> Bias As Long
> StandardName As String * 32
> StandardDate As Long
> StandardBias As Long
> DaylightName As String * 32
> DaylightDate As Long
> DaylightBias As Long
> End Type
>
> Declare Function GetTimeZoneInformation Lib "kernel32" _
> (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
>
> Function NowPlusTZBias() As Date
>
> Dim usrTZI As TIME_ZONE_INFORMATION
> Dim lngRetVal As Long
>
> lngRetVal = GetTimeZoneInformation(usrTZI)
> NowPlusTZBias = Now + (usrTZI.Bias / 1440)
> End Function
>
> To use it in the program, do this:
>
> 'If this is true, we're using Windows Time. Note that we have to
> 'compenstate for the timezone and use UTC. The NowPlusTZ Biaswas
> 'code taken from a MS access? newsgroup.
> data_out(1) = CByte(Year(NowPlusTZBias) - 2000)
> data_out(2) = CByte(Month(NowPlusTZBias))
> data_out(3) = CByte(Day(NowPlusTZBias))
> data_out(4) = CByte(Hour(NowPlusTZBias))
> data_out(5) = CByte(Minute(NowPlusTZBias))
> data_out(6) = CByte(Second(NowPlusTZBias))
>
>
> In other words, copy the first part into your code (as I did) and instead
> of using Now, use NowPlusTZBias
>
> --
> Magnus McElroy
> Electrical Engineer (EIT)
> HABIT Research
> (250) 381-9425[/color]

Is there a reason why seemingly nobody used the GetSystemTime funtion and
does all this crazy adding and subtracting?

Keith R. Weimer
Way Too Happy Software


Magnus McElroy
Guest
 
Posts: n/a
#4: Aug 19 '05

re: vb6 UTC time?




Keith R. Weimer wrote:
*snip*[color=blue]
>
>
> Is there a reason why seemingly nobody used the GetSystemTime funtion and
> does all this crazy adding and subtracting?
>
> Keith R. Weimer
> Way Too Happy Software
>[/color]

Nope, no reason. It was just the first solution I found. It works, so
there's no point in changing it.

--
Magnus McElroy
Electrical Engineer (EIT)
HABIT Research
(250) 381-9425
Closed Thread