/** * Date date = new Date(); * //Wed Nov 02 16:27:40 CST 2022 * //方法一 * LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); * //2022-11-02T16:27:40.918 * //方法二 * LocalDateTime localDateTime1 = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); * * * //LocalDateTime 转 Date * * Date date1 = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); */
Date date = new Date();
//Wed Nov 02 16:27:40 CST 2022
//方法一
LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
//2022-11-02T16:27:40.918
//方法二
LocalDateTime localDateTime1 = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
//LocalDateTime 转 Date
Date date1 = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());