我有一个文本框,用户可以在估计时间内输入,例如可能是150小时。我该如何格式化?时间自动格式化到00:00:00
所以如果我在150个小时内进入其更改为34.22:59:59
格式化时间大于24小时
TimeSpan tmpEstimate;
TimeSpan? TimeEstimate;
if (TimeSpan.TryParse(txtEstimateHrs.Text, out tmpEstimate))
TimeEstimate = tmpEstimate;
else
TimeEstimate = null;
用户将只能在输入时间,所以我不需要格式化几分钟或几秒钟,但现场也可以因此它需要接受空时间到
更完整:'double tmpEstimate;如果(double.TryParse(txtEstimateHrs.Text,outtmpEstimate)) {TimeEstimate = TimeSpan.FromHours(tmpEstimate);其他 {TimeEstimate = null; }根据需要,空白文本字段将转到“else”分支。 –
@JeppeStigNielsen谢谢你,自由地编辑答案。至少,我的:) – Backs
TimeEstimate仍在格式化小时。如果我输入150 TimeEstimate将150更改为'6.06:00:00' – user123456789