c#写一个计时器

using System;
using System.Runtime.InteropServices.ComTypes;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dt = DateTime.Now;
            int m = 0,h=0,s=0;
            Console.WriteLine("当前日期:{0}", dt);
            int a=int.Parse(Console.ReadLine());
            int b = a / 60;
            for (int i=1;i<=a+1;i++)
            {
                if(s==60)
                {
                    m++;
                    s = 0;
                    if (m == 60)
                    {
                        h++;
                        m = 0;
                    }
                }
                Console.Write("{0:D2}", h);
                Console.Write(":");
                Console.Write("{0:D2}", m);
                Console.Write(":");
                Console.Write("{0:D2}", s);
                Console.Write("\r");
                if (i+1 > a + 1)
                    break;
                Thread.Sleep(1000);
                s+=1;
            }
            
        }
    }
}

你可能感兴趣的:(c#)