/*TimeSpan structure(구조체)*/

class Program
{
    public static void Main()
    {
        TrisCls nm=new TrisCls();
        nm.running();
    }
}
class TrisCls
{
    //properties
    Timer tm;
    DateTime now,startdate,enddate;
    TimeSpan dateDiff;
    int diff_day,diff_hour,diff_minute,diff_second;

    public void running()
    {
        tm=new Timer();
        tm.Elapsed += new ElapsedEventHandler(____time_tick);
        tm.Interval = 500;
        tm.Start();

        now = DateTime.Now;
        startdate = Convert.ToDateTime(now.ToString("yyyy-MM-dd HH:mm:ss"));

        while(true)
        {
            keyinfo = Console.ReadKey(true);

            if(keyinfo.Key==ConsoleKey.Escape) break;
        }

        tm.Stop();
        tm.Elapsed -= ____time_tick;
    }
    void ____time_tick(object sender, ElapsedEventArgs e)
    {
        now = DateTime.Now;
        enddate=Convert.ToDateTime(now.ToString("yyyy-MM-dd HH:mm:ss"));

        dateDiff = enddate - startdate;

        diff_day = dateDiff.Days;
        diff_hour = dateDiff.Hours;
        diff_minute = dateDiff.Minutes;
        diff_second = dateDiff.Seconds;

        log("Time");
    }
    void log(string msg)
    {
        Console.WriteLine("Event:[" msg + "]" + ">>>>"
                       + diff_day + "/" + diff_hour + "/" + diff_minute + "/" + diff_scond);
    }
}

+ Recent posts