源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

解析c#显示友好时间的实现代码

  • 时间:2022-12-18 17:07 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:解析c#显示友好时间的实现代码
[u]复制代码[/u] 代码如下:
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) {   return "not yet"; } if (delta < 1 * MINUTE) {   return ts.Seconds == 1 ? "1秒前" : ts.Seconds + "秒前"; } if (delta < 2 * MINUTE) {   return "1分钟之前"; } if (delta < 45 * MINUTE) {   return ts.Minutes + "分钟"; } if (delta < 90 * MINUTE) {   return "1小时前"; } if (delta < 24 * HOUR) {   return ts.Hours + "小时前"; } if (delta < 48 * HOUR) {   return "昨天"; } if (delta < 30 * DAY) {   return ts.Days + " 天之前"; } if (delta < 12 * MONTH) {   int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30));   return months <= 1 ? "一个月之前" : months + "月之前"; } else {   int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365));   return years <= 1 ? "一年前" : years + "年前"; }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部