日,时,分,两个日期之间秒两个、日期

2023-09-02 10:38:13 作者:苦涩灬回忆卐

我有两个日期,一个比另一个更小。我想创建一个字符串,如这一个

I have two dates, one less than the other. I want to create a string such as this one

0天0小时23分18秒。

"0 days, 0 hours, 23 minutes, 18 seconds"

重新presenting两个日期之间的差。我怎样才能得到这个字符串的这些元素?

representing the difference between the two dates. How can I get these elements of this string?

推荐答案

时间跨度是你需要的对象:

TimeSpan span = (DateTime.Now - DateTime.Now);

String.Format("{0} days, {1} hours, {2} minutes, {3} seconds", 
    span.Days, span.Hours, span.Minutes, span.Seconds);