int i=121;
print(ParseTimeSeconds(i));
结果为”2:01″
///<summary>
///由秒数得到日期几天几小时。。。
///</summary
///<param name="t">秒数</param>
///<param name="type">0:转换后带秒,1:转换后不带秒</param>
///<returns>几天几小时几分几秒</returns>
public static string ParseTimeSeconds(int t, int type=0)
{
string r = "";
int day, hour, minute, second;
if (t >= 86400) //天,
{
day = Convert.ToInt16(t / 86400);
hour = Convert.ToInt16((t % 86400) / 3600);
minute = Convert.ToInt16((t % 86400 % 3600) / 60);
second = Convert.ToInt16(t % 86400 % 3600 % 60);
if (type == 0)
r = day + (":") + hour + (":") + minute + (":") + second + (":");
else
r = day + (":") + hour + (":") + minute + (":");
}
else if (t >= 3600)//时,
{
hour = Convert.ToInt16(t / 3600);
minute = Convert.ToInt16((t % 3600) / 60);
second = Convert.ToInt16(t % 3600 % 60);
if (type == 0)
r = hour + (":") + (minute<10? ("0"+ minute) : minute.ToString()) + (":") + (second < 10 ? ("0" + second) : second.ToString());
else
r = hour + (":") + minute + (":");
}
else /* if (t >= 60)//分*/
{
minute = Convert.ToInt16(t / 60);
second = Convert.ToInt16(t % 60);
r = (minute < 10 ? ("0" + minute) : minute.ToString()) + (":") + (second < 10 ? ("0" + second) : second.ToString());
}
return r;
}
版权声明:本文为u011590556原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。