25 lines
838 B
Java
25 lines
838 B
Java
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 + "时";
|
||
}
|
||
}
|
||
}
|