(如何展示分钟,用秒表秒) [英] How show minutes and seconds with Stopwatch()

查看:184
本文介绍了(如何展示分钟,用秒表秒)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也需要展现分钟,其实我用这个代码秀秒,但也需要几分钟

I need to show also the minutes, actually I use this code for show the seconds, but also need the minutes

TimeSpan ts = stopwatch.Elapsed;
Console.WriteLine("File Generated: " + _writer.getBinaryFileName(filePath, Convert.ToInt32(logSelected)) + " in "  + "{0}.{1:D2}" + "seconds", 
    ts.Seconds, 
    ts.Milliseconds/10 + "\n"
);



我该怎么办?

how can I do?

推荐答案

您应该使用:

ts.ToString("mm\\:ss\\.ff")

这会给你分钟,秒和在百分之的时间间隔。

this will give you minutes, seconds and the hundredths of a second in a time interval.

也看看 http://msdn.microsoft.com/en-us/library/ee372287.aspx

编辑:
哦,如果你想成为分钟,你可以做以下你最大的单位:

EDITED: well if you want minutes be your biggest unit you can do the following:

string.Format("{0}:{1}", Math.Floor(ts.TotalMinutes), ts.ToString("ss\\.ff"))

这篇关于(如何展示分钟,用秒表秒)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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