Stopwatch watch = Stopwatch.StartNew();

//要执行的方法

test();

watch.Stop();
Console.WriteLine(string.Format("耗时:{0}", formatDuring(watch.ElapsedMilliseconds)));
Console.ReadKey();

//毫秒转成天小时分钟

public static String formatDuring(long mss)
{
long days = mss / (1000 * 60 * 60 * 24);
long hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
long minutes = (mss % (1000 * 60 * 60)) / (1000 * 60);
long seconds = (mss % (1000 * 60)) / 1000;
long ms = 0;
if (seconds == 0)
{
ms = mss;
}
return days + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒" + ms + "毫秒";
}

posted on 2019-08-11 10:17  红磨坊后的白桦树  阅读(179)  评论(0编辑  收藏  举报