Days, hours, minutes, seconds between two dates

后端 未结 9 1054
挽巷
挽巷 2020-12-01 07:29

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

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

representing the differenc

9条回答
  •  离开以前
    2020-12-01 07:51

    How about something like this?

        TimeSpan diff = dateTimeNew - dateTimeOld;
        string output = string.Format("{0} days, {1} hours, {2} minues, {3} seconds", diff.Days, diff.Hours, diff.Minutes, diff.Seconds);
        Console.WriteLine(output);
    

提交回复
热议问题