Vb.net时差2按钮 [英] Vb.net time difference 2 button

查看:88
本文介绍了Vb.net时差2按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个按钮可以获得我的系统时间。

 DateTime.Now.ToString 

所以问题是如何才能获得两个时间的差异由2个按钮显示到2个文本框



我需要这个差异是可变的因为生病保存到我的数据库中



我尝试了什么:



 '  button1  

Timer2.Start()
TextBox1.Text = DateTime.Now。 ToString( hh:mm:ss tt


' button2

Timer2.Start()
TextBox2。 Text = DateTime.Now.ToString( hh:mm:ss tt







i试图把它作为button2

 label1.Text = DateDiff(   n,DateTime.Parse(TextBox2.Text),DateTime.Parse(TextBox1.Text)) .ToString 

但它给出负数 ex:-2(分钟)

所以请帮我提高代码

解决方案

例如:

  Dim  startTime < span class =code-keyword> As  DateTime 
Dim endTime As DateTime
Dim duration As TimeSpan


< span class =code-comment>' button1
starttime = DateTime.Now

button2
endtime = DateTime.Now

' 计算时差
持续时间= endTime - startTime







欲了解更多详情,请参阅:

TimeSpan Structure(System) [ ^ ]


你的DateDiff参数轮回错误,参见 DateDiff函数(Visual Basic) [ ^ ]。



但是,Maciej提供了上述最佳解决方案。


i have 2 button that get my system time.

DateTime.Now.ToString

so the problem is how can i get the difference of two time by 2 button and displayed to 2 textbox

and i need that difference to be variable because ill save it into my database

What I have tried:

'button1

        Timer2.Start()
        TextBox1.Text = DateTime.Now.ToString("hh:mm:ss tt")


'button2

        Timer2.Start()
        TextBox2.Text = DateTime.Now.ToString("hh:mm:ss tt")




i tried to put this is button2

label1.Text = DateDiff("n", DateTime.Parse(TextBox2.Text), DateTime.Parse(TextBox1.Text)).ToString

but it gives the negative number ex: -2 (minutes)
so please help me to enchance the code

解决方案

For example:

Dim startTime As DateTime
Dim endTime As DateTime
Dim duration As TimeSpan


'button1
starttime = DateTime.Now

'button2
endtime = DateTime.Now

'calculate time difference
duration = endTime - startTime




For further details, please see:
TimeSpan Structure (System)[^]


Your DateDiff parameters are the wrong way round, see DateDiff Function (Visual Basic)[^].

However, Maciej has provided the best solution above.


这篇关于Vb.net时差2按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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