标签:ant 时间 表示 cal now() alt offset with day
// 日期
LocalDate date = LocalDate.of(2021, 1, 11);
// 时间
LocalTime time = LocalTime.of(20, 53);
// 日期时间
LocalDateTime datetime = LocalDateTime.of(date, time);
// LocalDateTime datetime = LocalDateTime.of(2017, 10, 22, 10, 10, 10);
当前年:2021
当前月:1
当前日:9
在本年第9日
在本年第9星期
LocalDateTime now = LocalDateTime.now();
System.out.println("当前年:"+now.getYear());
System.out.println("当前月:"+now.getMonthValue());
System.out.println("当前日:"+now.getDayOfMonth());
System.out.println("在本年第"+now.getDayOfMonth()+"日");
System.out.println("在本年第"+now.getDayOfMonth()+"星期");
本月第n天日期:2021-01-01T21:55:24.022
本年第n天日期:2021-12-31T21:55:24.022
System.out.println("本月第n天日期:"+now.withDayOfMonth(1));
System.out.println("本年第n天日期:"+now.withDayOfYear(365));
now = 2021-01-09T21:58:10.240
修改月份,日期不变:2021-02-09T21:58:10.240
修改小时:2021-01-09T20:58:10.240
// 修改年月日
System.out.println("修改月份,日期不变:" + now.withMonth(2));
System.out.println("修改小时:"+now.withHour(20));
23:59:59.999999999
00:00
System.out.println(LocalTime.MAX);
System.out.println(LocalTime.MIN);
long nowTime = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
long zeroTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).toInstant(ZoneOffset.of("+8")).toEpochMilli();
if (LocalTime.of(20, 50).isBefore(now)
&& LocalTime.MAX.isAfter(now)) {
return "error datetime.";
}
标签:ant 时间 表示 cal now() alt offset with day
原文地址:https://www.cnblogs.com/xiongyungang/p/14256671.html