/// <summary>
/// 获得本地时间戳毫秒
/// </summary>
/// <returns></returns>
public static long GetTime() {
return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;
}
/// <summary>
/// 获得本地时间戳秒
/// </summary>
/// <returns></returns>
public static long GetTim()
{
return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
}
/// <summary>
/// 传一个时间戳得一个经过时间
/// </summary>
/// <param name="timer">毫秒</param>
/// <returns></returns>
public static string GetTimer(string timer)
{
long ti = GetTime() - long.Parse(timer);
if (ti / 60000 >= 1)
{
if (ti / 3600000 >= 1)
{
if (ti / 86400000 >= 1)
{
int num = (int)(ti / 86400000);
return num + "天以前";
}
else
{
int num = (int)(ti / 3600000);
return num + "小时以前";
}
}
else
{
int num = (int)(ti / 60000);
return num + "分钟以前";
}
}
else
{
return "刚刚";
}
}
/// <summary>
/// 传入一个秒数返回字符串时间格式
/// </summary>
/// <param name="timer"></param>
/// <returns></returns>
public static string GetStrTimer(long timer, string typ)
{
string st = "";
if (typ == "00:00")
{
if (timer > 60)
{
int second = (int)(timer % 60);
int minute = (int)((timer - second) / 60);
string str;
if (minute >= 10)
{
str = minute.ToString();
}
else
{
str = "0" + minute.ToString();
}
if (second >= 10)
{
return str + ":" + second;
}
else
{
return str + ":00";
}
}
else
{
if (timer >= 10)
{
return "00:" + timer;
}
else
{
return "00:0" + timer;
}
}
}
else if (typ == "00:00:00")
{
}
return st;
}
|