二、返回差值時間#region 二、返回差值時間
返回差值時間#region 返回差值時間
/**//// <summary>
/// 返回差值時間
/// </summary>
/// <param name="dt">時間</param>
/// <returns>回差值時間 </returns>
public static string ChangeTime(object dt)
...{
DateTime Dtnow = DateTime.Now;
TimeSpan ts = Dtnow - DateTime.Parse(dt.ToString());
string txt = "分鐘前";
float s = float.Parse(ts.TotalMinutes.ToString());
if (s<1)
二、返回差值時間#region 二、返回差值時間
返回差值時間#region 返回差值時間
/**//// <summary>
/// 返回差值時間
/// </summary>
/// <param name="dt">時間</param>
/// <returns>回差值時間 </returns>
public static string ChangeTime(object dt)
...{
DateTime Dtnow = DateTime.Now;
TimeSpan ts = Dtnow - DateTime.Parse(dt.ToString());
string txt = "分鐘前";
float s = float.Parse(ts.TotalMinutes.ToString());
if (s<1)
...{
s = s/43200;
txt = "個月前";
}
else if (s>518400)
...{
s = s/518400;
txt = "年前";
}
int a = Convert.ToInt32(System.Math.Round(s));
return a.ToString() + txt;
}
/**//// <summary>
/// 精確到秒的返回方法
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public static string ChangeTimeSecond(object dt)
...{
DateTime Dtnow = DateTime.Now;
TimeSpan ts = Dtnow - DateTime.Parse(dt.ToString());
string txt = "分鐘前";
float s = float.Parse(ts.TotalMinutes.ToString());
if (s<1)
...{
s = (float)ts.TotalSeconds;
if(s <= 0)
...{
s = (float)1.1;
}
txt = "秒鐘前";
}
else if (s>60 && s<1440)
...{
s = (float)ts.TotalHours;
txt = "小時前";
}
else if (s>1440 && s<43200)
...{
s = (float)ts.TotalDays;
txt = "天前";
}
else if (s>43200 && s<518400)
...{
s = s/43200;
txt = "個月前";
}
else if (s>518400)
...{
s = s/518400;
txt = "年前";
}
int a = Convert.ToInt32(System.Math.Round(s));
return a.ToString() + txt;
}
#endregion