我需要获得两个ZonedDateTime实例来表示当前周的开始和结束.
ZonedDateTime currentDateTime = ZonedDateTime.now();
ZonedDateTime startOfThisWeek = currentDateTime.with(DayOfWeek.MONDAY).truncatedTo(ChronoUnit.DAYS).plusMinutes(1);
ZonedDateTime endOfThisWeek = startOfThisWeek.plusDays(6);
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd kk:mm");
String startweek = startOfThisWeek.format(df);
String endweek = endOfThisWeek.format(df);
System.out.println(startweek);
System.out.println(endweek);
Run Code Online (Sandbox Code Playgroud)
输出:
2018-06-18 24:01
2018-06-24 24:01
Run Code Online (Sandbox Code Playgroud)
这个字符串代表什么?是在2018-06-18上午午夜后1分钟?如果是这样,为什么24:01是有效时间?我认为在24小时制表示中它应该是00:01.
编辑:有没有办法格式化这个显示00:01而不将字符串转换为新的字符串?