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());
	}

}

    文章標籤

    JAVA LocalDateTime Date

    全站熱搜

    咪卡恰比 發表在 痞客邦 留言(0) 人氣()