解析c#顯示友好時間的實現(xiàn)代碼
更新時間:2013年05月18日 11:13:49 作者:
本篇文章是對c#中顯示友好時間的實現(xiàn)代碼進行了介紹,需要的朋友參考下
復制代碼 代碼如下:
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#采用OpenXml實現(xiàn)給word文檔添加文字
這篇文章主要介紹了C#采用OpenXml實現(xiàn)給word文檔添加文字的方法,包括了用法的實例分析,是非常實用的技巧,需要的朋友可以參考下2014-09-09詳解Unity使用ParticleSystem粒子系統(tǒng)模擬藥水在血管中流動(粒子碰撞)
這篇文章主要介紹了Unity使用ParticleSystem粒子系統(tǒng)模擬藥水在血管中流動(粒子碰撞),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-05-05C#創(chuàng)建一個小型Web Server(Socket實現(xiàn))
這篇文章主要介紹了關于C#利用Socket實現(xiàn)創(chuàng)建一個小型Web Server的相關資料,文中通過示例代碼介紹的很詳細,需要的朋友可以參考借鑒,下面來一起看看吧。2017-02-02