Datetime.now as TimeSpan value?

前端 未结 7 1386
小蘑菇
小蘑菇 2020-12-17 09:00

I need the current Datetime minus myDate1 in seconds.

DateTime myDate1 = new DateTime(1970, 1, 9, 0, 0, 00);
DateTime myDate2 = DateTime.Now;

T         


        
相关标签:
7条回答
  • 2020-12-17 09:55

    You can use Subtract method:

    DateTime myDate1 = new DateTime(1970, 1, 9, 0, 0, 00);
    DateTime myDate2 = DateTime.Now;
    TimeSpan ts = myDate2.Subtract(myDate1);
    MessageBox.Show(ts.TotalSeconds.ToString());
    
    0 讨论(0)
提交回复
热议问题