File tree Expand file tree Collapse file tree
core-java-modules/core-java-8/src/main/java/com/wdbyte Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -161,15 +161,29 @@ public void calcTest() {
161161 public void timeFunctionTest () {
162162 LocalDateTime now = LocalDateTime .now ();
163163 System .out .println ("当前时间:" + now );
164- // 第一天
164+
165+ // LocalDateTime 本月第一天
166+ // 方法1
165167 LocalDateTime firstDay = now .withDayOfMonth (1 );
166168 System .out .println ("本月第一天:" + firstDay );
167- // 当天最后一秒
168- LocalDateTime lastSecondOfDay = now .withHour (23 ).withMinute (59 ).withSecond (59 );
169- System .out .println ("当天最后一秒:" + lastSecondOfDay );
170- // 最后一天
169+ // 方法2
170+ firstDay = now .with (TemporalAdjusters .firstDayOfMonth ());
171+ System .out .println ("本月第一天:" + firstDay );
172+
173+ // LocalDateTime 本月最后一天
171174 LocalDateTime lastDay = now .with (TemporalAdjusters .lastDayOfMonth ());
172175 System .out .println ("本月最后一天:" + lastDay );
176+
177+
178+ // LocalDateTime 当天最后一秒
179+ // 方法1
180+ LocalDateTime lastSecondOfDay1 = now .withHour (23 ).withMinute (59 ).withSecond (59 );
181+ System .out .println ("当天最后一秒:" + lastSecondOfDay1 );
182+ // 方法2
183+ LocalDateTime lastSecondOfDay2 = LocalDateTime .now ().with (LocalTime .MAX );
184+ System .out .println ("当天最后一秒:" + lastSecondOfDay2 );
185+
186+
173187 // 是否闰年
174188 System .out .println ("今年是否闰年:" + Year .isLeap (now .getYear ()));
175189 }
You can’t perform that action at this time.
0 commit comments