java.time.LocalDateTime to java.util.Date
import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; import org.junit.Test; public class LocalDateTimeTest { @Test public void toDate(){ LocalDateTime testLDT = LocalDateTime.now(); Date testD = Date.from(testLDT.atZone(ZoneId.systemDefault()).toInstant()); System.out.println(testD.toString()); LocalDateTime testLDT2 = LocalDateTime.ofInstant(testD.toInstant(), ZoneId.systemDefault()); System.out.println(testLDT2.toString()); } }
文章標籤
全站熱搜
留言列表