安卓中制造一个显示使用了多少时间的方法
2016-05-07 15:28
513 查看
本代码意在计算一个过程所消耗的时间,然后将时间以人可以很方便的角度显示出来。
设置两个Button按钮,一个为start,一个为stop。在主活动中也定义这两个变量long start=0,stop。start为起始时间,stop为终止时间。详细实现代码如下:
start=System.currentTimeMillis();
stop=System.currentTimeMillis();
if(start!=0){
long result=stop-start;//定义一个result用来保存时间差
int mil,sec,min,hour;
mil=(int)(result%1000);
sec=(int)(result/1000);
min=(int)(sec/60);
hour=(int)(min/60);
sec=sec%60;
min=min%60;
//showResult为textview控件,这里定义变量名为showResult。
showResult.setText(String.format("%d:%02d:%02d.%d",hour,min,sec,mil));
}
设置两个Button按钮,一个为start,一个为stop。在主活动中也定义这两个变量long start=0,stop。start为起始时间,stop为终止时间。详细实现代码如下:
start=System.currentTimeMillis();
stop=System.currentTimeMillis();
if(start!=0){
long result=stop-start;//定义一个result用来保存时间差
int mil,sec,min,hour;
mil=(int)(result%1000);
sec=(int)(result/1000);
min=(int)(sec/60);
hour=(int)(min/60);
sec=sec%60;
min=min%60;
//showResult为textview控件,这里定义变量名为showResult。
showResult.setText(String.format("%d:%02d:%02d.%d",hour,min,sec,mil));
}
相关文章推荐
- 将ROI区域继续划分成4*4小格,求取每4小格组成的1个box区域的Hue(色调)通道直方图
- C语言的基本数据类型总结
- [error handle]Linux下配置mysql的编码
- 软考程序员随笔-----2
- 个人对插件和钩子的理解
- 天的故事 V1.0.2
- 个人模板记录♪(^∇^*)♪(^∇^*)♪(^∇^*)
- 基于bootstrap插件实现autocomplete自动完成表单
- Linux05--Shell程序设计01
- linux进程优先级、进程nice/renice设置
- web项目异常A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister
- poj 1840 Eqs
- Windows Tftpd32 DHCP服务器 使用
- 【01背包】HDU1421搬寝室
- 图形界面中如何控制在文本框里面只能输入数字字符
- Spring 4 MVC HelloWorld 纯注解方式(带源码)【超赞】
- 关系数据库SQL之高级数据查询:去重复、组合查询、连接查询、虚拟表
- ViewPagerIndicator使用
- MapReduce基本原理与WordCount程序
- Yii-自我参考手册