Simulate the release time of the circle of friends and format the past time to xx (seconds/minute/hour/day ).
Simulate the release time of the circle of friends, and use the extension method to display the past time as xx (seconds/minute/hour/day), take the message time in the message list as an example, let's take a look at the direct Time Display Effect (date. toString ("yyyy/MM/dd HH: mm: ss "))
I feel very general, nothing special
Next we will write an extension method to format the message time to xx (seconds/minute/hour/day) before
Decimal. Truncate (data) // retrieves the entire decimal number.
Public static class HtmlExpansion {// only formats the time in the past two days. public static string agdatefomat (this DateTime date) {var times = DateTime. now-date; var s = Convert. toDecimal (times. totalSeconds); // second var m = Convert. toDecimal (times. totalMinutes); // minute var h = Convert. toDecimal (times. totalHours); // hour var d = Convert. toDecimal (times. totalDays); // return s <60? "" + Decimal. Truncate (s) + "seconds ago": m <60? "" + Decimal. Truncate (m) + "Minutes Ago": h <24? "" + Decimal. Truncate (h) + "Hours Ago": d <2? "" + Decimal. Truncate (d) + "Days Ago": date. ToString ("yyyy/MM/dd HH: mm: ss ");}}
Call date. agdatefomat () directly after date. The result is as follows:
Does it feel a little higher than the previous time?
==== End ====