Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Button = 500
IDC_TextBoxIn
IDC_TextBoxOut
End Enum
Global hDlg As Dword
Function PBMain() As Long
Dialog Default Font "Tahoma",12,1
Dialog New Pixels, 0, "UTC to Local Time Converter",300,300,400,130, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Convert", 50,10,100,25
Control Add TextBox, hDlg, %IDC_TextBoxIn,"Date: Tue, 3 Jan 2017 22:27:31 +0400 (GMT)",20,40,360,30
Control Add TextBox, hDlg, %IDC_TextBoxOut,"",20,80,360,30
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local iHour, iMinute, iSecond, iDay, iMonth, iYear, iZoneMinutes, iPos As Long, temp$, tmp$
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
Control Get Text hDlg, %IDC_TextBoxIn To temp$
iPos = InStr(temp$,"(")
If iPos Then temp$ = Left$(temp$,iPos-1)
iDay = Val(Parse$(temp$,$Spc,3))
iMonth = InStr("JanFebMarAprMayJunJulAugSepOctNovDec",Parse$(temp$,$Spc,4))/3+1
iYear = Val(Parse$(temp$,$Spc,5))
tmp$ = Parse$(temp$,$Spc,6) '22:27:31 hr:min:sec
iHour = Val(Parse$(tmp$,":",1))
iMinute = Val(Parse$(tmp$,":",2))
iSecond = Val(Parse$(tmp$,":",3))
tmp$ = Parse$(temp$,$Spc,7) '+0400
iZoneMinutes = SGN(VAL(tmp$)) * (VAL(MID$(tmp$,2,2)) * 60 + VAL(RIGHT$(tmp$,2)))
ConvertUTC(iDay,iMonth,iYear,iHour,iMinute,iSecond,iZoneMinutes)
End Select
End Select
End Function
Sub ConvertUTC(iDay As Long, iMonth As Long, iYear As Long, iHour As Long, iMinute As Long, iSecond As Long, iZoneMinutes As Long)
Local MyTime As IPowerTime, LocalTimeString$, temp$
Let MyTime = Class "PowerTime"
? Str$(iDay) + Str$(iMonth) + Str$(iYear) + Str$(iZoneMinutes) + Str$(iHour) + Str$(iMinute) + Str$(iSecond)
MyTime.NewDate(iYear, iMonth, iDay) 'UTC time
MyTime.NewTime(iHour, iMinute, iSecond) 'UTC time
MyTime.AddMinutes(-iZoneMinutes) 'Time Zone adjustment in Minutes
MyTime.ToLocalTime 'Convert UTC to Local time
LocalTimeString$ = Left$(MyTime.DayOfWeekString,3) + "," + _
Str$(MyTime.Day) + $Spc + _
Left$(MyTime.MonthString,3) + _
Str$(MyTime.Year) + $Spc + _
Left$(MyTime.TimeStringFull,8)
Control Set Text hDlg, %IDC_TextBoxOut, LocalTimeString$
End Sub
http://www.garybeene.com/sw/gbsnippets.htm