Difference between two DateTimes C#?

后端 未结 6 651
借酒劲吻你
借酒劲吻你 2020-12-24 04:08

I need a function that can return the difference between the below two dates as 24.

DateTime a = new DateTime(2008, 01, 02, 06, 30, 00);
DateTime b = new Dat         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 05:02

    You can do the following:

    TimeSpan duration = b - a;
    

    There's plenty of built in methods in the timespan class to do what you need, i.e.

    duration.TotalSeconds
    duration.TotalMinutes
    

    More info can be found here.

提交回复
热议问题