您好,欢迎访问一九零五行业门户网

C# 显示过去了多长时间的函数

c#  显示过去了多长时间的函数
public string howlongbeforenow { get { var ts = new timespan(datetime.utcnow.ticks - createddate.ticks); var delta = ts.totalseconds; const int second = 1; const int minute = 60 * second; const int hour = 60 * minute; const int day = 24 * hour; const int month = 30 * day; if (delta < 0) { throw new invaliddataexception("the createddate can not be gather than 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 < 45 * minute) { return ts.minutes + " minutes ago"; } if (delta < 90 * minute) { return "1 hour ago"; } if (delta < 24 * hour) { return ts.hours + " hours ago"; } if (delta < 48 * hour) { return "yesterday"; } if (delta < 30 * day) { return ts.days + " days ago"; } if (delta < 12 * month) { var months = convert.toint32(math.floor((double)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; }
以上就是c#  显示过去了多长时间的函数的内容。
其它类似信息

推荐信息