【Android 时钟(由秒转变为时分秒)】花门楼前见秋草,岂能贫贱相看老。这篇文章主要讲述Android 时钟(由秒转变为时分秒)相关的知识,希望能为你提供帮助。
int second = 0;
Handler handler = new Handler(); handler.post(runnable); Runnable runnable = new Runnable() { @Override public void run() { second++; patrol_time_txt.setText(Util.getTime(second)); handler.postDelayed(runnable, 1000); } };
//根据秒数转化为时分秒00:00:00
public static String getTime(int second) { if (second < 10) { return "00:0" + second; } if (second < 60) { return "00:" + second; } if (second < 3600) { int minute = second / 60; second = second - minute * 60; if (minute < 10) { if (second < 10) { return "0" + minute + ":0" + second; } return "0" + minute + ":" + second; } if (second < 10) { return minute + ":0" + second; } return minute + ":" + second; } int hour = second / 3600; int minute = (second - hour * 3600) / 60; second = second - hour * 3600 - minute * 60; if (hour < 10) { if (minute < 10) { if (second < 10) { return "0" + hour + ":0" + minute + ":0" + second; } return "0" + hour + ":0" + minute + ":" + second; } if (second < 10) { return "0" + hour + minute + ":0" + second; } return "0" + hour + minute + ":" + second; } if (minute < 10) { if (second < 10) { return hour + ":0" + minute + ":0" + second; } return hour + ":0" + minute + ":" + second; } if (second < 10) { return hour + minute + ":0" + second; } return hour + minute + ":" + second; }
推荐阅读
- 问题MappingJacksonHttpMessageConverter ClassNotFoundException
- Unity调用Android的Activity
- 关于Android Studio导出jar包的问题
- android NDK开发中,用Cygwin调试本地代码时报错“Another debug session running,Use --force to kill it”原因及解决的方法
- 安卓之父造手机(该紧张的只有iPhone())
- Android 编译错误——布局 Error parsing XML: not well-formed (invalid token)
- sendkeys && appactivate
- Android开发笔记(12)——ListView & Adapter
- 一步一步实现android studio代码上传到github。