SpringBoot日期格式的使用总结
数据库日期类型 date
java Date LocalDateTime
日期类型的相互转换
//两种日期类型的声明方式
LocalDateTime localDateTime=LocalDateTime.now();
Date date = new Date();
//LocalDateTime转为Date类型
LocalDateTime expectTime = workTicketBaseInfo.getExpectTime();
Date expectdate = Date.from(expectTime.atZone(ZoneId.systemDefault()).toInstant());
// 创建一个java.util.Date对象
Date date = new Date();
LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
//将日期字符串解析为 LocalDateTime 对象
LocalDateTime parse1 = LocalDateTime.parse("2023-10-03 00:00:00", DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));
Oracle中计算两个日期相差的毫秒值
select ceil((To_date('2023-10-03 00:00:00' , 'yyyy-mm-dd hh24-mi-ss') - To_date('2023-10-01 23:59:59' , 'yyyy-mm-dd hh24-mi-ss')) * 24 * 60 * 60 * 1000) 相差豪秒数 FROM DUAL;
-- oracle Date类型转换为字符串
select F_WORK_TICKET_REST_TIME(to_char(t.expect_time,'yyyy-mm-dd hh24:mi:ss')) as rest_time from TR_WORK_TICKET t