当前位置:首页 > Java API 与类库手册 > 正文

Java优学网LocalTime教程:轻松掌握时间处理与冲突检测

org.threeten threetenbp 1.6.8

LocalTime currentTime = LocalTime.now();

public class MeetingRoomBooking {

private LocalTime startTime;
private LocalTime endTime;

public boolean hasConflict(MeetingRoomBooking other) {
    return !(this.endTime.isBefore(other.startTime) || 
            this.startTime.isAfter(other.endTime));
}

}

public LocalTime convertToTargetTimeZone(LocalTime sourceTime, ZoneId sourceZone, ZoneId targetZone) {

// 假设源时间是某时区的上午9点
ZonedDateTime sourceZoned = ZonedDateTime.of(
    LocalDate.now(), sourceTime, sourceZone
);

ZonedDateTime targetZoned = sourceZoned.withZoneSameInstant(targetZone);
return targetZoned.toLocalTime();

}

Java优学网LocalTime教程:轻松掌握时间处理与冲突检测

你可能想看:

相关文章:

文章已关闭评论!