将两次之间的差异转换为毫秒? [英] Convert Difference between 2 times into Milliseconds?

查看:23
本文介绍了将两次之间的差异转换为毫秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个屏蔽的 TextBox 控件,想知道如何在每个控件中获取时间,然后将差异转换为毫秒.比如,在 tb1 中我写12:01",在 tb2 中我写12:02",然后单击一个按钮.单击按钮后,它将启动一个计时器,并在 12:02 显示一个消息框.除了时间转换部分,我知道怎么做.

I have two masked TextBox controls and was wondering how I'd go about getting the time in each one and then converting the difference into milliseconds. Like, say in tb1 I write "12:01" and in tb2 I write "12:02", and then click a button. Once the button's clicked it starts a timer and at 12:02 a messagebox will be displayed. I know how to do all of it except for the time conversion part.

如何实现?

推荐答案

DateTime dt1 = DateTime.Parse(maskedTextBox1.Text);
DateTime dt2 = DateTime.Parse(maskedTextBox2.Text);
TimeSpan span = dt2 - dt1;
int ms = (int)span.TotalMilliseconds;

这篇关于将两次之间的差异转换为毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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