Question Pulling time from servers

vamshivemula

New member
Joined
Feb 25, 2010
Messages
3
Programming Experience
1-3
Hi,

My requirement is to pull time from TIME SERVERS through .NET code to avoid time manipulation in my project which needs to record time for users when they start particular task and system clock can be changed to record wrong timings. I need to pull this time in IST.

I was able to get some links but unable to write codeThe links are:
NIST Internet time service
ftp://time-a.nist.gov/pub/daytime/
NIST Internet Time Service clock
Current local time in India

One of the above link has source code of windows utility in C# which I am not familiar with. We can just get the code from the utility that just queries the server and then use the time. We have to make the application to randomly choose a server from a list of servers if you have query lots of times as they deny requests if queried multiple times in a period.

Please help me with sample code.


CROSS POSTING: I have also posted this same question in this VBDOTNETFORUMS in "Windows Forms Discussion related to Winforms application development Thread" too.
 
Last edited:

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,744
Location
Sydney, Australia
Programming Experience
10+
Please do not post each question more than once. Your other thread has been deleted.

If you have C# code then you can use one of the various online code converters to convert it to VB. It generally won't do a perfect job but it should get you fairly close and you can always ask here about any specific issues.
 

vamshivemula

New member
Joined
Feb 25, 2010
Messages
3
Programming Experience
1-3
Found the solution for the question I posted. Though, it is not perfect, I am able to continue on my project temporarily and if anyone can come up with better solution please help me. I have used a multiline Textbox (txtPageSource) which is in hidden state on the form to put the extracted Web site page source to use for coding.

Private Function getPageSource(ByVal URL As String) As String
Dim getWebClient As System.Net.WebClient = New System.Net.WebClient()
Dim strSource As String = getWebClient.DownloadString(URL)
getWebClient.Dispose()
Return strSource
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myPageSource, myStr, myStr1, strDate As String
Dim curLen, myStrPos, setStartPos As Integer
Dim dt As DateTime

txtPageSource.Text = getPageSource("http://www.worldtimeserver.com/current_time_in_IN.aspx")
myPageSource = txtPageSource.Text

'code to trim all the text till TIME start position
myStr = "<span class=""font7"">"
myStrPos = myPageSource.IndexOf(myStr)
txtPageSource.Text = txtPageSource.Text.Remove(1, myStrPos + 23)
myPageSource = txtPageSource.Text

'code to trim all the text till after DATE
curLen = Len(txtPageSource.Text)
myStr1 = "2010"
setStartPos = myPageSource.IndexOf(myStr1)
txtPageSource.Text = txtPageSource.Text.Remove(setStartPos + 4, curLen - setStartPos - 4)

'code to trim "</span>" and "</div>" tags in between TIME and DATE
' 6:27 AM
' </span>
'</div>
'Wednesday, June 23, 2010
txtPageSource.Text = txtPageSource.Text.Replace("</span>", "")
txtPageSource.Text = txtPageSource.Text.Replace("</div>", "")

strDate = txtPageSource.Text
dt = CType((TypeDescriptor.GetConverter(New DateTime(2000, 1, 1)).ConvertFrom(strDate)), DateTime)
'txtPageSource.Text = dt
MsgBox(dt)
End Sub




Vamshi Vemula
 
Top Bottom