Implementation method of Android timer and time calculator

Demand: the default is "00:00:00". When you click the start button, reset and start timing, such as 10:28:34. Stop timing when you click stop. Problem: using the calendar dateformat method, if the time zone is not set, the obtained hours are in the local time zone (8 in the East eighth zone). If the GMT standard time zone is set, the obtained time is 12 hours (12:00:00). Setting the 24-hour system is invalid. The addition and subtraction of various hours in the start time is invalid, and the timing can only jump up automatically after 12 hours. The effect of starting timing at 00:00:00 by default cannot appear. After trying various time setting methods are invalid, you can only write a method to convert the time format string according to the number of seconds. After testing, it is no problem. The two digits can only display 99 hours as the maximum. If you need to change the size of hours, you need to change the method. In addition, the number of hours cannot be infinite. If the length exceeds the long data type, it will become negative and an exception will occur.

Display effect:

Test class:

Practical examples:

Test code in time format:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>