PDA

View Full Version : نمایش ساعت از سایت time.ir



tahsin
شنبه 09 فروردین 1399, 23:43 عصر
با سلام

من میخام ساعت رو از سایت time.ir بگیرم و نمایش بدم. چطوری میتونم این کار رو انجام بدم؟ ممنون

the king
یک شنبه 10 فروردین 1399, 07:29 صبح
با سلام

من میخام ساعت رو از سایت time.ir بگیرم و نمایش بدم. چطوری میتونم این کار رو انجام بدم؟ ممنون

توصیه می کنم اینکار رو نکنید، از سرویس سایتی استفاده کنید که خودش تمایل به اینکار رو داشته باشه و سرویس دادن رو هم برای شما ساده کنه،

Plain text (http://worldtimeapi.org/api/timezone/Asia/Tehran.txt)

JSON (http://worldtimeapi.org/api/timezone/Asia/Tehran)


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

tahsin
دوشنبه 11 فروردین 1399, 12:15 عصر
ممنونم از شما