<dependency> <groupId>net.time4j</groupId> <artifactId>time4j-core</artifactId> <version>4.40</version> </dependency> PlainDate date = SystemClock.inLocalView().today(); PlainTime time = SystemClock.inLocalView().currentTime(); ChronoFormatter<PlainDate> dateFormatter = ChronoFormatter.ofPattern("yyyy-MM-dd", PatternType.CLDR, Locale.CHINA); ChronoFormatter<PlainTime> timeFormatter = ChronoFormatter.ofPattern("HH:mm:ss", PatternType.CLDR, Locale.CHINA); String formattedDate = dateFormatter.format(date); String formattedTime = timeFormatter.format(time); PlainDate parsedDate = dateFormatter.parse(formattedDate); PlainTime parsedTime = timeFormatter.parse(formattedTime); Duration<?> oneDay = Duration.of(1, CalendarUnit.DAYS); PlainDate tomorrow = date.plus(oneDay); PlainTime twoHoursLater = time.plus(2, ClockUnit.HOURS); Interval<PlainTime> timeRange = Interval.between(time, twoHoursLater); Duration<?> rangeDuration = timeRange.getDuration(); ChronoFormatter<Interval<PlainTime>> rangeFormatter = ChronoFormatter.ofMomentInterval( "HH:mm:ss - HH:mm:ss", PatternType.CLDR, Locale.CHINA); String formattedTimeRange = rangeFormatter.format(timeRange);


上一篇:
下一篇:
切换中文