在控制台上显示时间 [英] displaying time on console

查看:141
本文介绍了在控制台上显示时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

你知道time()函数用于在c中查找时间,并以秒为单位返回值,我希望在控制台上连续显示时间(如一个数字时钟),这意味着在一个小时内只有分钟和秒钟会改变(如果代码保持运行)...

有没有任何功能可以帮助我这样做?

如果你发现问题愚蠢,我很抱歉:(

解决方案

很抱歉,你的问题确实有点愚蠢,考虑到谷歌可能有给你一个答案。

http:// www.dreamincode.net/forums/topic/62217-clock-in-c-console/ [ ^ ]



祝你好运!


  var 秒表=  new  System.Diagnostics.Stopwatch(); 
stopwatch.Start();

// 这里正在进行我的流程





TimeSpan ts =秒表。累计;





{0}分钟+{1}秒(秒),ts.Minutes,ts.Seconds,ts.Milliseconds / 10.



秒表秒表=新秒表();

秒表。开始();

而(真实)

{

TimeSpan timeSpan = TimeSpan.FromSeconds(Convert.ToInt32(stopwatch.Elapsed.TotalSeconds));

Console.Write(timeSpan.ToString(c));

Console.Write( ''\ r'');

}


hey,
you know that the time() function is used to find out time in c,and it returns the value in seconds,I wish to display the time continuously on a console(like a digital clock),which means that within one hour only the minutes and seconds shall change(if the code is kept running)...
Is there any function which could help me do this???
My apologies if you find the question dumb:(

解决方案

Sorry to say your question is indeed kind of dumb, considering google could have given you an answer straight away.
http://www.dreamincode.net/forums/topic/62217-clock-in-c-console/[^]

Good luck!


var stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();

//here is doing my process



TimeSpan ts = stopwatch.Elapsed;


{0} minute(s)"+ " {1} second(s)", ts.Minutes, ts.Seconds, ts.Milliseconds/10.

Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
while (true)
{
TimeSpan timeSpan = TimeSpan.FromSeconds(Convert.ToInt32(stopwatch.Elapsed.TotalSeconds));
Console.Write(timeSpan.ToString("c"));
Console.Write(''\r'');
}


这篇关于在控制台上显示时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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