很想要用Java的时间api,但有时候还是需要转换为Date. 二者的相互转换并不是一步到位那么简单,所以,还是需要记录一下转换的api Date to LocalDateTime Date todayDate = new Date(); LocalDateTime ldt = todayDate.toInstant() .atZone( ZoneId.systemDefault() ) .toLocalDateTime(); System.out.println(ldt); //2019-05…
LocalDateTime 转 Date LocalDateTime localDateTime=LocalDateTime.now() Date date = Date.from(localDateTime.atZone( ZoneId.systemDefault()).toInstant()); Date 转 LocalDateTime Date startDate=new Date(); LocalDateTime localDateTime = startDate.toInstant()…
import java.time.*;import java.time.format.DateTimeFormatter;import java.time.format.DateTimeFormatterBuilder;import java.time.temporal.ChronoField;import java.util.Date; public class LocalDateTimeUtil { public static final String YYYY = "yyyy";…