במקרים מהסוג הזה בודקים מול הזמן המקומי מהאינטרנט
הנה קוד לדוגמא:
Function InternetTime(Optional GMTDifference As Integer) As Date
'-----------------------------------------------------------------------------------
'This function returns the Greenwich Mean Time retrieved from an internet server.
'You can use the optional argument GMTDifference in order to add (or subtract)
'an hour from the GMT time. For Example if you call the function as:
'=InternetTIme(2) it will return the (local) hour GMT + 2. Note that the
'GMTDifference variable is an integer number.
'Written by: Christos Samaras
'Date: 25/09/2013
'Last Updated: 10/01/2017
'e-mail: <לא ניתן לפרסם מיילים באופן פומבי>
'site:
https://myengineeringworld.net/////
'-------------------------------------------------------------------------------
'Declaring the necessary variables.
Dim Request As Object
Dim ServerURL As String
Dim Results As String
Dim NetDate As String
Dim NetTime As Date
Dim LocalDate As Date
Dim LocalTime As Date
'Check if the time difference is within the accepted range.
If GMTDifference < -12 Or GMTDifference > 14 Then
Exit Function
End If
'The server address.
ServerURL = "
https://www.timeanddate.com/worldclock/fullscreen.html"
'Build the XMLHTTP object and check if was created successfully.
On Error Resume Next
Set Request = CreateObject("MSXML2.ServerXMLHTTP.6.0")
If Err.Number <> 0 Then
Exit Function
End If
On Error GoTo 0
'Create the request.
Request.Open "GET", ServerURL, False, "", ""
'Send the request to the internet server.
Request.Send
'Based on the status node result, proceed accordingly.
If Request.ReadyState = 4 Then
'If the request succeed, the following line will return
'something like this: Mon, 30 Sep 2013 18:33:23 GMT.
Results = Request.getResponseHeader("date")
'Use the Mid function to get something like: 30 Sep 2013 18:33:23.
Results = Mid(Results, 6, Len(Results) - 9)
'Use the Left and Right function to distinguish the date and time.
NetDate = Left(Results, Len(Results) - 9) '30 Sep 2013
NetTime = Right(Results, 8) '18:33:23
'Convert the date into a valid Excel date 30 Sep 2013 -> 30/9/2013.
'Required for countries that have some non-Latin characters at their alphabet (Greece, Russia, Serbia etc.).
LocalDate = ConvertDate(NetDate)
'Add the hour difference to the retrieved GMT time.
LocalTime = NetTime + GMTDifference / 24
'Return the local date and time.
InternetTime = LocalDate + LocalTime
End If
'Release the XMLHTTP object.
Set Request = Nothing
End Function
Function ConvertDate(strDate As String) As Date
'-------------------------------------------------------------------------
'This function converts the input date into a valid Excel date.
'For example the 30 Sep 2013 becomes 30/9/2013.
'Required for countries that have non-Latin characters at their alphabet.
'Written by: Christos Samaras
'Date: 25/09/2013
'e-mail: <לא ניתן לפרסם מיילים באופן פומבי>
'site:
https://myengineeringworld.net/////
'-------------------------------------------------------------------------
'Declaring the necessary variables.
Dim MyMonth As Integer
'Check the month and convert it to number.
Select Case UCase(Mid(strDate, 4, 3))
Case "JAN": MyMonth = 1
Case "FEB": MyMonth = 2
Case "MAR": MyMonth = 3
Case "APR": MyMonth = 4
Case "MAY": MyMonth = 5
Case "JUN": MyMonth = 6
Case "JUL": MyMonth = 7
Case "AUG": MyMonth = 8
Case "SEP": MyMonth = 9
Case "OCT": MyMonth = 10
Case "NOV": MyMonth = 11
Case "DEC": MyMonth = 12
End Select
'Rebuild the date.
ConvertDate = DateValue(Right(strDate, 4) & "/" & MyMonth & "/" & Left(strDate, 2))
End Function
אתה קורא לפונקציה InternetTime
ושולח לה כפרמטר את המספר 2 כדי לקבל את הזמן המקומי בישראל (+2)
(במקרה שלך תחייב אותו להיות מחובר לאינטרנט כדי לפתוח את התוכנה...)
בהצלחה