如何以字符串格式 (01:30:24) 从特定时间开始计时? [Android]
How do i start chronometer from specific time in string format (01:30:24)? [Android]
如何在字符串格式的计时器中设置开始时间(例如 - 01:30:24)?
Nb:android 使用 Kotlin
根据这个post的回答,
我想你想要达到的是这个。
//1. parse your input as a date object.
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
Date startDate = format.parse("01:30:00");
//2. feed it to a Calendar Object
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
//3. get the hour, minute, second variable
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
//4. apply to your Chronometer class.
mChronometer.setBase(SystemClock.elapsedRealtime() - (hour * 60000 * 60 + minute * 60000 + second * 1000)))
希望对您有所帮助。
如何在字符串格式的计时器中设置开始时间(例如 - 01:30:24)?
Nb:android 使用 Kotlin
根据这个post的回答,
我想你想要达到的是这个。
//1. parse your input as a date object.
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
Date startDate = format.parse("01:30:00");
//2. feed it to a Calendar Object
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
//3. get the hour, minute, second variable
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
//4. apply to your Chronometer class.
mChronometer.setBase(SystemClock.elapsedRealtime() - (hour * 60000 * 60 + minute * 60000 + second * 1000)))
希望对您有所帮助。