This question already has answers here:
java date format with 6 digit micro/milli second
                                
                                    (3个答案)
                                
                        
                        
                            java.util.Date format SSSSSS: if not microseconds what are the last 3 digits?
                                
                                    (5个答案)
                                
                        
                        
                            SimpleDateFormat cannot parse milliseconds with more than 4 digits
                                
                                    (7个答案)
                                
                        
                        
                            Java date parsing with microsecond or nanosecond accuracy
                                
                                    (2个答案)
                                
                        
                                2年前关闭。
            
                    
我有以下值:
2018-01-16-18.56.57.300000

它被传递给方法参数:“值”。

private Timestamp getPossibleTimestampI(String value) {

   SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss.SSS");
    Date parsedDate;
    Timestamp timestamp=null;
    try {
        parsedDate = dateFormat.parse(value);
        timestamp = new java.sql.Timestamp(parsedDate.getTime());
    } catch (ParseException e1) {
        e1.printStackTrace();
    }

return timestamp;
}


我正在获取一个Timestamp对象,其值为2018-01-16 19:01:57.0,与原始字符串值相比大约多了5分钟。

为什么会这样,我该如何纠正转换?

最佳答案

在时间2018-01-16-18.56.57.300000,您的300000毫秒将转换为分钟

which is 300000/60000 = 5 minutes

10-06 05:49
查看更多