نوشته شده توسط
tahsin
با سلام
من میخام ساعت رو از سایت time.ir بگیرم و نمایش بدم. چطوری میتونم این کار رو انجام بدم؟ ممنون
توصیه می کنم اینکار رو نکنید، از سرویس سایتی استفاده کنید که خودش تمایل به اینکار رو داشته باشه و سرویس دادن رو هم برای شما ساده کنه،
Plain text
JSON
Public Class Form1
Private Const City As String = "Asia/Tehran"
Private WithEvents _timer As New Timer
Private ReadOnly _label As New Label
Private ReadOnly _stopwatch As New Stopwatch
Private _time As DateTime
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim client As New Net.WebClient
Dim timedata = client.DownloadString("http://worldtimeapi.org/api/timezone/" & City & ".txt")
_stopwatch.Start()
Dim lines = timedata.Split(New String() {vbCrLf, vbCr, vbLf}, StringSplitOptions.None)
For Each line In lines
Dim pos = line.IndexOf("datetime:", StringComparison.Ordinal)
If pos >= 0 Then
_time = DateTime.Parse(line.Substring(pos + 10))
_timer.Interval = 100
_timer.Enabled = True
Exit For
End If
Next
Catch ex As Exception
_label.Text = ex.Message
End Try
_label.Parent = Me
_label.Location = New Point(100, 100)
End Sub
Private Sub _timer_Tick(sender As Object, e As EventArgs) Handles _timer.Tick
_label.Text = _time.Add(_stopwatch.Elapsed)
End Sub
End Class