Datetime.now as TimeSpan value?

2019-01-25 05:28发布

I need the current Datetime minus myDate1 in seconds.

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

TimeSpan myDateResult = new TimeSpan();

myDateResult = myDate2 - myDate1;

.
.
I tried different ways to calculate but to no effect.

TimeSpan mySpan = new TimeSpan(myDate2.Day, myDate2.Hour, myDate2.Minute, myDate2.Second);

.
The way it's calculated doesn't matter, the output should just be the difference these to values in seconds.

7条回答
\"骚年 ilove
2楼-- · 2019-01-25 06:27

Have you tried something like

DateTime.Now.Subtract(new DateTime(1970, 1, 9, 0, 0, 00)).TotalSeconds

DateTime.Subtract Method (DateTime)

TimeSpan.TotalSeconds Property

查看更多
登录 后发表回答