C # shows how long a function has been in the past
public string Howlongbeforenow {get {var ts = new TimeSpan (datetime.utcnow.t Icks-createddate.ticks); var delta = ts. TotalSeconds; const int second = 1; const int minute = * SECOND; const int hour = * MINUTE; const INT day = * HOUR; const INT month = * DAY; if (Delta < 0) {throw new Invaliddataexception ("The createddate can not be gather th An today. "); if (Delta < 1 * minute) {return TS. Seconds = = 1? "1 second ago": TS. Seconds + "Seconds ago"; } if (Delta < 2 * minute) {return "1 minute ago"; } if (Delta < * minute) {return TS. Minutes + "Minutes ago"; } if (Delta < * minute) {return "1 hour ago"; } if (Delta < * hour) {return TS. Hours + "Hours ago"; } if (Delta < * hour) {return "Yesterday"; } if (Delta < * day) {return TS. Days + ' days ago '; } if (Delta < month) {var months = Convert.ToInt32 (Math.floor (d ouble) Ts. DAYS/30)); Return months <= 1? "1 month ago": Months + "months ago"; } var years = Convert.ToInt32 (Math.floor (double) ts. days/365)); Return years <= 1? "1 year ago": Years + "years ago"; } }
Css:
. how-long-ago { font-style:italic; Color: #777; }
These are the contents of the function that C # shows in the past, and more about topic.alibabacloud.com (www.php.cn)!