Calculate relative time in C#

后端 未结 30 2120
生来不讨喜
生来不讨喜 2020-11-21 05:59

Given a specific DateTime value, how do I display relative time, like:

  • 2 hours ago
  • 3 days ago
  • a month ago
30条回答
  •  无人共我
    2020-11-21 06:31

    using Fluent DateTime

    var dateTime1 = 2.Hours().Ago();
    var dateTime2 = 3.Days().Ago();
    var dateTime3 = 1.Months().Ago();
    var dateTime4 = 5.Hours().FromNow();
    var dateTime5 = 2.Weeks().FromNow();
    var dateTime6 = 40.Seconds().FromNow();
    

提交回复
热议问题