Calculate relative time in C#

后端 未结 30 2123
生来不讨喜
生来不讨喜 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:07

    When you know the viewer's time zone, it might be clearer to use calendar days at the day scale. I'm not familiar with the .NET libraries so I don't know how you'd do that in C#, unfortunately.

    On consumer sites, you could also be hand-wavier under a minute. "Less than a minute ago" or "just now" could be good enough.

提交回复
热议问题