手机
当前位置:查字典教程网 >编程开发 >C#教程 >解析c#显示友好时间的实现代码
解析c#显示友好时间的实现代码
摘要:复制代码代码如下:constintSECOND=1;constintMINUTE=60*SECOND;constintHOUR=60*MIN...

复制代码 代码如下:

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 + "年前";

}

【解析c#显示友好时间的实现代码】相关文章:

C# 无需COM组件创建快捷方式的实现代码

gridview 显示图片的实例代码

c# n个数排序实现代码

C#中让控件全屏显示的实现代码(WinForm)

C#中动态显示当前系统时间的实例方法

c#获取本机的IP地址的代码

c# 调用.bat文件的实现代码

C#加密解密文件小工具实现代码

关于c#二叉树的实现

C#截图程序类似腾讯QQ截图实现代码

精品推荐
分类导航