Files
ElderlyDialer/app/src/main/java/com/ttstd/dialer/utils/TimeUtils.java

25 lines
838 B
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.ttstd.dialer.utils;
import java.time.ZonedDateTime;
public class TimeUtils {
public static String formatToHourDescription(String isoTimeString) {
// 解析输入的时间字符串(例如:"2026-03-19T00:00+08:00"
ZonedDateTime inputTime = ZonedDateTime.parse(isoTimeString);
// 获取当前时间,使用与输入时间相同的时区
ZonedDateTime now = ZonedDateTime.now(inputTime.getZone());
// 提取输入时间的小时
int inputHour = inputTime.getHour();
int currentHour = now.getHour();
// 比较输入时间与当前时间的小时和日期
if (inputHour == currentHour && inputTime.toLocalDate().equals(now.toLocalDate())) {
return "现在";
} else {
return inputHour + "";
}
}
}