如何在VB.NET中以HH:mm:ss:fff格式减去两个不同的时间? [英] How to subtract two different time in HH:mm:ss:fff format in VB.NET ?

查看:101
本文介绍了如何在VB.NET中以HH:mm:ss:fff格式减去两个不同的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

公共类Form1 
私有 Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理Button1.Click
TextBox1.Text =格式(现在, HH:mm:ss:fff)'开始按钮
结束 Sub

私人 Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理Button2.Click
TextBox2.Text =格式(现在, HH:mm:ss:fff)'结束按钮
结束 Sub

Private Sub Button3_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button3.Click
'减法按钮
TextBox3 .Text = TextBox2.Text - TextBox1.Text
结束 Sub
End Class





以上代码出现以下错误。





从字符串12:00:03:554转换为Double无效。

解决方案

不要为 start end 按钮格式化字符串。使用 Date.Now 及其日期和时间。

为了能够获得时差,请使用 DateDiff [ ^ ]功能。



另一个方法是使用 TimeSpan [ ^ ]结构

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = Format(Now, "HH:mm:ss:fff") ' start button
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox2.Text = Format(Now, "HH:mm:ss:fff") ' end button
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'subtract button
        TextBox3.Text = TextBox2.Text - TextBox1.Text
    End Sub
End Class



for the above code the following error is coming.


Conversion from string "12:00:03:554" to type 'Double' is not valid.

解决方案

Do not format string for start and end button. Use Date.Now with the date and time.
To be able to get time difference, use DateDiff[^] function.

Another way is to use TimeSpan[^] structure.


这篇关于如何在VB.NET中以HH:mm:ss:fff格式减去两个不同的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆