如何从倒计时中删除毫秒? [英] How do I remove milliseconds from time countdown?
本文介绍了如何从倒计时中删除毫秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为给定的时间间隔创建一个计时器,该计时器应在达到限制时执行操作。例如,如果时间从上午9:25起倒数10.30 Am。 (01:12.16)秒。它不应该显示毫秒。
我尝试过:
无效t_Tick(对象发送者,EventArgs e)
{Timespan tt = end.subtract(DateTIme.Now);
Tb.text = string。格式({0}秒左右,TT);
}
I'm trying to create a timer for a given time interval that should take an action when the limit is reached. For instance, if the time clocks 10.30 Am as it counts down from 9:25 am. (01:12.16) seconds remaining. It should not show the milliseconds.
What I have tried:
Void t_Tick(object sender, EventArgs e)
{Timespan tt = end.subtract(DateTIme.Now);
Tb.text = string. Format ({0} seconds left", TT);
}
推荐答案
参见 C#中的日期和时间格式 [ ^ ]
以下内容不会显示毫秒数,可根据您的日期格式要求进行调整
DateTime.Now.ToString(MM / dd / yyyy HH:mm:ss)
See Date And Time Format In C#[^]
The following will not display milliseconds and can be adjusted to suit your date format requirements
DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")
解决方案#1非常好,并展示了如何处理日期格式的方法。
至于你的代码,请检查:
Solution #1 is very good and shows a way how to deal with date formats.
As to your code, check this:
Void t_Tick(object sender, EventArgs e)
{
Timespan tt = end.Subtract(DateTIme.Now)
int sec = tt.Seconds;
Tb.text = string.Format({0} seconds left", sec);
}
详情请见:TimeSpan.Seconds属性(系统)| Microsoft Docs [ ^ ]
这篇关于如何从倒计时中删除毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文