Posted: Fri Aug 02, 2002 12:06 am
				
				Restored from previous forum. Originally posted by scurrier.
ever see programs that go out and get the time from an internet time server
well here's on written in PB 3.2 enjoy
;
; Free Time
; Coded by Sean Currier
;
Buffer = AllocateMemory(0, 1000, 0)
Global buffer
Global port
Global tzone.l
Dim TimeZone.s(15)
timezone(1)="Atlantic Daylight Time"
timezone(2)="Atlantic Standard Time"
timezone(3)="Eastern Daylight Time"
timezone(4)="Eastern Standard Time"
timezone(5)="Central Daylight Time"
timezone(6)="Central Standard Time"
timezone(7)="Mountain Daylight Time"
timezone(8)="Mountain Standard Time"
timezone(9)="Pacific Daylight Time"
timezone(10)="Pacific Standard Time"
timezone(11)="Alaska Daylight Time"
timezone(12)="Alaska Standard Time"
timezone(13)="Hawaii-Aleutian Daylight Time"
timezone(14)="Hawaii-Aleutian Standard Time"
timezone(15)="Samoa Standard Time"
Procedure GetInternetTime()
Repeat
ConnectionID = OpenNetworkConnection("208.184.49.9", Port)
If ConnectionID
ReceiveNetworkData(ConnectionID, Buffer, 1000)
a$=PeekS(Buffer)
hour$=Mid(a$,17,2)
min$=Mid(a$,20,2)
sec$=Mid(a$,23,2)
month$=Mid(a$,11,2)
year$=Mid(a$,8,2)
day$=Mid(a$,14,2)
EndIf
SetGadgetText(2,hour$+":"+min$+":"+sec$)
hour=(Val(hour$)-tzone)
hour$=Str(hour)
If Len(hour$)=1
hour$="0"+hour$
EndIf
SetGadgetText(5,hour$+":"+min$+":"+sec$)
Delay(1000) ; the delay's are needed or the time server will drop the connection
ForEver
EndProcedure
Procedure CurrentTime()
Repeat
GetTime()
hour.l=Hour()
If Len(hour$)=1
hour$="0"+Str(hour)
Else
hour$=Str(hour)
EndIf
min.l=Minute()
min$=Str(min)
If Len(min$)=1
min$="0"+Str(min)
Else
min$=Str(min)
EndIf
sec.l=Second()
sec$=Str(sec)
If Len(sec$)=1
sec$="0"+Str(sec)
Else
sec$=Str(sec)
EndIf
Time$=hour$+":"+min$+":"+sec$
SetGadgetText(4,Time$)
Delay(1)
ForEver
EndProcedure
ThreadID1=CreateThread(@GetInternetTime(), 154)
ThreadID2=CreateThread(@CurrentTime(), 156)
Port = 13
If InitNetwork() = 0
MessageRequester("Error", "Can't initialize the network !", 0)
End
EndIf
If OpenWindow(1,250,450,400,250,#PB_Window_SystemMenu,"Free Time Written By Sean Currier")
If CreateGadgetList(WindowID())
;uttonGadget(1, 120, 220, 150, 25, "Up-Date System Time")
TextGadget(12,20,20,130,21,"Internet UTC Time",#PB_Text_Center )
TextGadget(2,20,40,130,21,"Checking.....",#PB_Text_Border ) ; this is the time that gets updated
TextGadget(7,20,65,130,21,"Your Current Time",#PB_Text_Center )
TextGadget(4,20,85,130,21,"Checking.....",#PB_Text_Border )
TextGadget(8,20,115,130,21,"The Correct Time",#PB_Text_Center )
TextGadget(5,20,135,130,21,"Checking.....",#PB_Text_Border )
TextGadget(6,200,20,130,21,"Pick Your Time Zone",#PB_Text_Center )
ComboBoxGadget(3,160,40,220, 180,#PB_ComboBox_UpperCase )
EndIf
EndIf
For x=1 To 15
AddGadgetItem(3, -1, TimeZone(x))
Next x
Result = SetGadgetState(3, -1)
;
; Main Loop
;
Repeat
WNDevent=WindowEvent()
gagetevent = EventGadgetID()
GagetState = GetGadgetState(3)
Select GagetState ; pick the time zone
Case 0
tzone=3 ;Atlantic Daylight Time subtract 3 hours from UTC
Case 1
tzone=4 ;Atlantic Standard Time subtract 4 hours from UTC
Case 2
tzone=4 ;Eastern Daylight Time subtract 4 hours from UTC
Case 3
tzone=5 ;Eastern Standard Time subtract 5 hours from UTC
Case 4
tzone=5 ;Central Daylight Time subtract 5 hours from UTC
Case 5
tzone=6 ;Central Standard Time subtract 6 hours from UTC
Case 6
tzone=6 ;Mountain Daylight Time subtract 6 hours from UTC
Case 7
tzone=7 ;Mountain Standard Time subtract 7 hours from UTC
Case 8
tzone=7 ;Pacific Daylight Time subtract 7 hours from UTC
Case 9
tzone=8 ;Pacific Standard Time subtract 8 hours from UTC
Case 10
tzone=8 ;Alaska Daylight Time subtract 8 hours from UTC
Case 11
tzone=9 ;Alaska Standard Time subtract 9 hours from UTC
Case 12
tzone=9 ;Hawaii-Aleutian Daylight Time subtract 9 hours from UTC
Case 13
tzone=10 ;Hawaii-Aleutian Standard Time subtract 10 hours from UTC
Case 14
tzone=10 ;Samoa Standard Time subtract 11 hours from UTC
Default
tzone=0
EndSelect
;Delay(1)
Until WNDevent=#PB_EventCloseWindow
KillThread(ThreadID1)
KillThread(ThreadID2)
End
			ever see programs that go out and get the time from an internet time server
well here's on written in PB 3.2 enjoy
;
; Free Time
; Coded by Sean Currier
;
Buffer = AllocateMemory(0, 1000, 0)
Global buffer
Global port
Global tzone.l
Dim TimeZone.s(15)
timezone(1)="Atlantic Daylight Time"
timezone(2)="Atlantic Standard Time"
timezone(3)="Eastern Daylight Time"
timezone(4)="Eastern Standard Time"
timezone(5)="Central Daylight Time"
timezone(6)="Central Standard Time"
timezone(7)="Mountain Daylight Time"
timezone(8)="Mountain Standard Time"
timezone(9)="Pacific Daylight Time"
timezone(10)="Pacific Standard Time"
timezone(11)="Alaska Daylight Time"
timezone(12)="Alaska Standard Time"
timezone(13)="Hawaii-Aleutian Daylight Time"
timezone(14)="Hawaii-Aleutian Standard Time"
timezone(15)="Samoa Standard Time"
Procedure GetInternetTime()
Repeat
ConnectionID = OpenNetworkConnection("208.184.49.9", Port)
If ConnectionID
ReceiveNetworkData(ConnectionID, Buffer, 1000)
a$=PeekS(Buffer)
hour$=Mid(a$,17,2)
min$=Mid(a$,20,2)
sec$=Mid(a$,23,2)
month$=Mid(a$,11,2)
year$=Mid(a$,8,2)
day$=Mid(a$,14,2)
EndIf
SetGadgetText(2,hour$+":"+min$+":"+sec$)
hour=(Val(hour$)-tzone)
hour$=Str(hour)
If Len(hour$)=1
hour$="0"+hour$
EndIf
SetGadgetText(5,hour$+":"+min$+":"+sec$)
Delay(1000) ; the delay's are needed or the time server will drop the connection
ForEver
EndProcedure
Procedure CurrentTime()
Repeat
GetTime()
hour.l=Hour()
If Len(hour$)=1
hour$="0"+Str(hour)
Else
hour$=Str(hour)
EndIf
min.l=Minute()
min$=Str(min)
If Len(min$)=1
min$="0"+Str(min)
Else
min$=Str(min)
EndIf
sec.l=Second()
sec$=Str(sec)
If Len(sec$)=1
sec$="0"+Str(sec)
Else
sec$=Str(sec)
EndIf
Time$=hour$+":"+min$+":"+sec$
SetGadgetText(4,Time$)
Delay(1)
ForEver
EndProcedure
ThreadID1=CreateThread(@GetInternetTime(), 154)
ThreadID2=CreateThread(@CurrentTime(), 156)
Port = 13
If InitNetwork() = 0
MessageRequester("Error", "Can't initialize the network !", 0)
End
EndIf
If OpenWindow(1,250,450,400,250,#PB_Window_SystemMenu,"Free Time Written By Sean Currier")
If CreateGadgetList(WindowID())
;uttonGadget(1, 120, 220, 150, 25, "Up-Date System Time")
TextGadget(12,20,20,130,21,"Internet UTC Time",#PB_Text_Center )
TextGadget(2,20,40,130,21,"Checking.....",#PB_Text_Border ) ; this is the time that gets updated
TextGadget(7,20,65,130,21,"Your Current Time",#PB_Text_Center )
TextGadget(4,20,85,130,21,"Checking.....",#PB_Text_Border )
TextGadget(8,20,115,130,21,"The Correct Time",#PB_Text_Center )
TextGadget(5,20,135,130,21,"Checking.....",#PB_Text_Border )
TextGadget(6,200,20,130,21,"Pick Your Time Zone",#PB_Text_Center )
ComboBoxGadget(3,160,40,220, 180,#PB_ComboBox_UpperCase )
EndIf
EndIf
For x=1 To 15
AddGadgetItem(3, -1, TimeZone(x))
Next x
Result = SetGadgetState(3, -1)
;
; Main Loop
;
Repeat
WNDevent=WindowEvent()
gagetevent = EventGadgetID()
GagetState = GetGadgetState(3)
Select GagetState ; pick the time zone
Case 0
tzone=3 ;Atlantic Daylight Time subtract 3 hours from UTC
Case 1
tzone=4 ;Atlantic Standard Time subtract 4 hours from UTC
Case 2
tzone=4 ;Eastern Daylight Time subtract 4 hours from UTC
Case 3
tzone=5 ;Eastern Standard Time subtract 5 hours from UTC
Case 4
tzone=5 ;Central Daylight Time subtract 5 hours from UTC
Case 5
tzone=6 ;Central Standard Time subtract 6 hours from UTC
Case 6
tzone=6 ;Mountain Daylight Time subtract 6 hours from UTC
Case 7
tzone=7 ;Mountain Standard Time subtract 7 hours from UTC
Case 8
tzone=7 ;Pacific Daylight Time subtract 7 hours from UTC
Case 9
tzone=8 ;Pacific Standard Time subtract 8 hours from UTC
Case 10
tzone=8 ;Alaska Daylight Time subtract 8 hours from UTC
Case 11
tzone=9 ;Alaska Standard Time subtract 9 hours from UTC
Case 12
tzone=9 ;Hawaii-Aleutian Daylight Time subtract 9 hours from UTC
Case 13
tzone=10 ;Hawaii-Aleutian Standard Time subtract 10 hours from UTC
Case 14
tzone=10 ;Samoa Standard Time subtract 11 hours from UTC
Default
tzone=0
EndSelect
;Delay(1)
Until WNDevent=#PB_EventCloseWindow
KillThread(ThreadID1)
KillThread(ThreadID2)
End