생존기술_IT/JAVA

[JAVA] TIMESTAMP

LeCafeCreme 2020. 10. 3. 23:01

vnfvj2018. 9. 13. 16:49

출처 : infotake.tistory.com/16

 

1. 문자열 날짜를 Timestamp 변환 및 검증

java.sql.Timestamp timestamp_1 = java.sql.Timestamp.valueOf("2018-09-21 10:53:00.0");

System.out.format("timestamp : %s\r", timestamp_1.getTime());

System.out.format("date : %s\r\r", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(timestamp_1));

 

2. Java 로컬 날짜를 Timestamp 변환 및 검증

java.sql.Timestamp timestamp_2 = java.sql.Timestamp.valueOf(LocalDateTime.now());

System.out.format("timestamp : %s\r", timestamp_2.getTime());

java.sql.Date date = new java.sql.Date(timestamp_2.getTime());

System.out.format("date : %s\r\r", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(date));

 

3. 문자열 Timestamp 를 객체화, 변환 및 검증

java.sql.Timestamp timestamp_3 = new java.sql.Timestamp(Long.parseLong("1537495373964"));

System.out.format("timestamp : %s\r", timestamp_3.getTime());

System.out.format("date : %s", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new java.sql.Date(timestamp_2.getTime())));

 

출처 : infotake.tistory.com/16