哪位高手来解释一下这个程序

wu515200 2012-05-15 01:49:16
public string GetAllTime(int time)
{
string hh, mm, ss, fff;

int f = time%100; // 毫秒
int s = time/100; // 转化为秒
int m = s/60; // 分
int h = m/60; // 时
s = s%60; // 秒
//毫秒格式00
if(f<10)
{
fff = "0" + f.ToString();
}
else
{
fff = f.ToString();
}

//秒格式00
if(s<10)
{
ss = "0" + s.ToString();
}
else
{
ss = s.ToString();
}

//分格式00
if(m<10)
{
mm = "0" + m.ToString();
}
else
{
mm = m.ToString();
}

//时格式00
if(h<10)
{
hh = "0" + h.ToString();
}
else
{
hh = h.ToString();
}

//返回 hh:mm:ss.ff
return hh + ":" + mm + ":" + ss + "." + fff;
}

private void timer1_Tick(object sender, EventArgs e)
{

t = t + 1; //得到总的毫秒数
this.label7.Text = GetAllTime(t);



}
这个程序是关于秒时钟的,我看不是很懂,哪位高手可以来解读一下,比如:
public string GetAllTime(int time) 是什么意思,有什么作用?
还有: int f = time%100;是什么意思啊,
...全文
102 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
theillusion 2012-05-15
  • 打赏
  • 举报
回复
把int值转成字符串,如果时分秒是一位数的前面补零,比如 12:01:30.02。不过这个代码是蛇足,完全可以构造timespan然后tostring
bdmh 2012-05-15
  • 打赏
  • 举报
回复
就是对时间取得毫秒的信息,然后组合成字符串
ohkuy 2012-05-15
  • 打赏
  • 举报
回复

你看下t = t + 1; t的类型就知道了
将总时间刻度t转换成 hh:mm:ss.ff 的时候格式
fuermoshia 2012-05-15
  • 打赏
  • 举报
回复
public string GetAllTime(int time) 是什么意思,有什么作用?
就写的一个返回值为string类型的方法,下面那个timer不是调用了嘛
int f = time%100;是什么意思啊,
这个是定义一个int类型的f来接收time除以100的余数
mabaolin 2012-05-15
  • 打赏
  • 举报
回复
运行一下看看不就得了
cheng2005 2012-05-15
  • 打赏
  • 举报
回复
这些东西,只要你真正的对C#的语法,运算符能基础知识掌握了,肯定能看懂。
如果你这些基础都不知道,谁有兴趣给你讲那纯粹就是没事闲的。
mabaolin 2012-05-15
  • 打赏
  • 举报
回复
窝考~~

110,546

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧