Get DateTime.Now with milliseconds precision

前端 未结 11 1481
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 16:06

How can I exactly construct a time stamp of actual time with milliseconds precision?

I need something like 16.4.2013 9:48:00:123. Is this possible? I have an applic

11条回答
  •  庸人自扰
    2020-11-29 16:55

    This should work:

    DateTime.Now.ToString("hh.mm.ss.ffffff");
    

    If you don't need it to be displayed and just need to know the time difference, well don't convert it to a String. Just leave it as, DateTime.Now();

    And use TimeSpan to know the difference between time intervals:

    Example

    DateTime start;
    TimeSpan time;
    
    start = DateTime.Now;
    
    //Do something here
    
    time = DateTime.Now - start;
    label1.Text = String.Format("{0}.{1}", time.Seconds, time.Milliseconds.ToString().PadLeft(3, '0'));
    

提交回复
热议问题