从timepicker获取的Hours+Minutes中减去System.currentTimeMillis()的方法是将获取的时间转换为毫秒数,然后减去当前系统时间的毫秒数。
具体步骤如下:
以下是一个示例代码片段,演示如何实现上述步骤:
// 获取timepicker选择的小时和分钟数
int selectedHours = timePicker.getHours();
int selectedMinutes = timePicker.getMinutes();
// 将选择的时间转换为毫秒数
long selectedMilliseconds = (selectedHours * 60 * 60 * 1000) + (selectedMinutes * 60 * 1000);
// 获取当前系统时间的毫秒数
long currentMilliseconds = System.currentTimeMillis();
// 计算时间差
long timeDifference = selectedMilliseconds - currentMilliseconds;
// 将时间差转换为小时和分钟数
int hoursDifference = (int) (timeDifference / (60 * 60 * 1000));
int minutesDifference = (int) ((timeDifference % (60 * 60 * 1000)) / (60 * 1000));
// 输出结果
System.out.println("时间差为:" + hoursDifference + "小时 " + minutesDifference + "分钟");
这样,你就可以从从timepicker获取的Hours+Minutes中减去System.currentTimeMillis(),并得到时间差的小时和分钟数。
领取专属 10元无门槛券
手把手带您无忧上云