我有這個轉換問題。時間轉換爲秒
我有一個倒計時的秒錶。然後將其顯示在標籤上,使其在標籤(label1)上倒數時顯示爲「15:00:00」。
我還有一個每10秒一圈哪個循環秒錶時間和重疊時間保存到另一個標籤(標籤2)
那麼我是怎麼15:00:00?
我在我的表格中有3個文本框,第一個是幾個小時,第二個分鐘,第三個是第二個。 如果我在小時內輸入15,在分鐘和秒內輸入00並點擊按鈕1,它會自動將15小時(15:00:00)轉換爲保存在我的數據庫中的秒數,所以不是保存15:00:00,而是保存TotalSeconds這是54000秒。
當我的秒錶啓動時,它從數據庫獲取54000並再次將其轉換爲顯示在label1中的15:00:00。
我可以將標籤2(「13:00:00」)上的重疊時間轉換爲將轉換後的值顯示到另一個標籤(現在是label3)的秒數。
Imports System
Imports System.Timers
Public Class ClientDashboard
Dim StopWatch As New Stopwatch
Dim CountDown As TimeSpan
Dim IsRunning As Boolean = False
Private Shared timer As System.Timers.Timer
Private Sub ClientDashboard_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Sets dashboard to right
Me.Size = New System.Drawing.Size(317, 900)
Dim x As Integer
Dim y As Integer
x = Screen.PrimaryScreen.WorkingArea.Width - 317
y = Screen.PrimaryScreen.WorkingArea.Height - Screen.PrimaryScreen.WorkingArea.Height
Me.Location = New Point(x, y)
'get time of user
cn = New ADODB.Connection
Call conDB()
cn.Open()
Dim rs As New ADODB.Recordset
rs.Open("select * from tb_registration where=st_acc_number= '" & id_lbl.Text & "'", cn, 0, 3)
iduser_lbl.Text = "'" & rs("st_name").Value & "'""'" & rs("st_lname").Value & "'"
UserTotal.Text = rs("st_totaltimeleft").Value
'Start stopwatch
StopWatch.Start()
synchroUpdate.Enabled = True
synchroUpdate.Start()
Dim numSecs As Integer
Integer.TryParse(UserTotal.Text, numSecs)
CountDown = TimeSpan.FromSeconds(numSecs)
End Sub
Private Sub synchro_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles synchro.Tick
End Sub
'--------------------->>>> Methord 2 <<<<----------------------
Private Sub DispElaps(ByVal ts As TimeSpan, ByVal lbl As Label)
lbl.Text = String.Format("{0:00} : {1:00} : {2:00}", _
Math.Floor(ts.TotalHours), _
ts.Minutes, _
ts.Seconds, _
ts.Milliseconds)
End Sub
Private Sub synchroUpdate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles synchroUpdate.Tick
synchroUpdate.Interval = 100
'If countDown > stpw.Elapsed Then
Dim elaps As TimeSpan = CountDown - StopWatch.Elapsed
DispElaps(elaps, TimerOutput)
'Else
'End If
End Sub
Private Sub DoEvent()
timer = New System.Timers.Timer(5000)
AddHandler timer.Elapsed, AddressOf AC
timer.AutoReset = True
timer.Enabled = True
End Sub
'Address of event
Private Sub SaveEvent2(ByVal sender As System.Object, ByVal e As EventArgs)
AutoUpdate_Button.PerformClick()
End Sub
'Event Handler
Private Sub AC()
If Me.InvokeRequired Then
Me.Invoke(New MethodInvoker(AddressOf AC))
Else
Me.AutoUpdate_Button.PerformClick()
End If
End Sub
Private Sub logoutBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles logoutBTN.Click
End Sub
End Sub
End Class
顯示一些代碼... – OneFineDay
對不起。我在這個論壇上很新,對我很溫柔。 :) –