AdSense

網頁

2018/1/3

Java 移除Timestamp的毫秒

移除Timestamp的毫秒方法如下

long milliseconds= new Date().getTime();
long droppedMilliseconds = 1000 * (milliseconds / 1000); 
    
System.out.println(milliseconds);        // 1515044885894
System.out.println(droppedMilliseconds); // 1515044885000
    
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm.ss.SSS");
    
System.out.println(sdf.format(milliseconds));        // 2018-01-04 13:48.05.894
System.out.println(sdf.format(droppedMilliseconds)); // 2018-01-04 13:48.05.000
    
Timestamp t = new Timestamp(droppedMilliseconds);

參考:

沒有留言:

AdSense