【问题标题】:Conversion of time to seconds时间到秒的转换
【发布时间】:2014-01-17 00:08:08
【问题描述】:

我有这个转换问题。

我有一个倒计时的秒表。然后将其显示在标签上,以便在标签(label1)上显示如下“15:00:00”倒计时。

我还有另一个时间,每 10 秒循环一次,以圈秒表并将圈圈时间保存到另一个标签(label2)

那么我是怎么得到 15:00:00 的呢?

我的表单中有 3 个文本框,第一个是小时,第二个是分钟,第三个是秒。 如果我在小时输入 15,在分钟和秒输入 00 并点击按钮 1,它会自动将 15 小时(15:00:00)转换为保存在我的数据库中的秒,因此它不会保存 15:00:00,而是保存 TotalSeconds是 54000 秒。

当我的秒表启动时,它会从数据库中获取 54000 并再次将其转换为显示在 label1 中的 15:00:00。

我可以将 label2("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

【问题讨论】:

  • 对不起。我是这个论坛的新手,请对我温柔。 :)

标签: vb.net


【解决方案1】:

您的代码似乎为标签使用了好听的名称,但您的问题尚未更新为对应。

不过,您能否像使用 TimeSpan.TotalHours 一样使用 TimeSpan.TotalSeconds

【讨论】:

  • 我在下面找到了这段代码,并将其添加到单圈事件 Private Sub totalsec(ByVal fs As TimeSpan, ByVal lbl2 As Label) lbl2.Text = TimeSpan.Parse(Label5.Text) 中。 TotalSeconds 结束子
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-25
  • 1970-01-01
  • 2011-08-28
  • 2017-10-24
  • 1970-01-01
  • 2018-09-02
相关资源
最近更新 更多