我必须基于日期间隔显示进度条,前提是我已经指定了开始日期和结束日期,因此我们必须以这种方式在进度条中显示进度,以便如果您需要1-3天,那么应该填写相同的进度3至6,我们应该填写相同的进度...就像这样。
根据以下步骤给出开始日期和结束日期 1。然后找到总天数 2查找今天日期和开始日期之间的天数差异 3尝试根据我设置的mProgress.setProgress(degrees;)来获得今天和剩余天数之间的度差。
private void displayProgressView() {
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.circular);
final ProgressBar mProgress = (ProgressBar) findViewById(R.id.circularProgressbar);
mProgress.setProgress(0); // Main Progress
mProgress.setSecondaryProgress(360); // Secondary Progress
mProgress.setMax(360); // Maximum Progress
mProgress.setProgressDrawable(drawable);
int noOfDaysLeft = noOfDaysLeft();
final int degrees = getDregeesFordays(totalDays() - noOfDaysLeft);
textView.setText(noOfDaysLeft() + "\nday" + (noOfDaysLeft() == 1 ? "" : "s"));
mProgress.setProgress(degrees);
}
here is date
"startDate": "2019-09-12T15:48:12.293Z",
"endDate": "2019-10-12T08:19:00.710Z",
我想基于3的倍数来设置进度,例如如果我们的日差值是1,2,3,那么它应该显示相同的进度,然后是4,5,6,然后是第二进度,以此类推...等等。>
答案 0 :(得分:0)
val offset = OffsetDateTime.now().offset
val startDateEpoch = [your starting date in LocalDateTime unit].toEpochSecond(offset)
val endDateEpoch = [your end date in LocalDateTime unit].toEpochSecond(offset)
计算result = endDateEpoch - startDateEpoch
将其翻译为几天
eg. result = 500000
timeDifference = result / (3600 * 24)
... additional algorithm
if(timeDifference >= 1 && timeDifference <= 3) doA()
else if(timeDifference >= 4 && timeDifference <= 7) doB()
...additional algorithm
更新:如何构建LocalDateTime单位
val dayOfMonth = 23
val year = 2001
val month = 3
val hour = 0
val minute = 0
val myDate = LocalDate.of(year, month, dayOfMonth)
val myTime = LocalTime.of(hour, minute)
val startDateTime = LocalDateTime.of(myDate, myTime)