基本上我试图将字符串数据转换为Timestamp格式。当我将数据转换为时间戳格式时,SimpleDateFormat添加了三分钟。 由于毫秒数据等于3分钟,但我想保留时间戳值的毫秒数据。如何在java上保存milisecond数据simpledateFormat
代码:
public Double TimestampTest(String Timestamp){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date parsedDate = null;
try {
parsedDate = dateFormat.parse(Timestamp);
} catch (ParseException e1) {
e1.printStackTrace();
}
Timestamp timestamp = new java.sql.Timestamp(parsedDate.getTime());
...
}
Timestamp值
2002-04-17 23:45:58.983
对于测试用例
System.out.println(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse("2015-04-22T19:54:11.219983Z"));
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS'Z'").parse("2015-04-22 19:54:11.219983Z"));
结果是相同的为两者
Wed Apr 22 19:57:50 EEST 2015
Wed Apr 22 19:57:50 EEST 2015
因为
219 983 milliseconds = 3.66638333 minutes
总之我想保留MS数据。是有没有办法做到这一点?
'SimpleDateFormat'具有毫秒精度 - 小数点后3位数。如果有3个以上,你会得到奇怪的结果:https://stackoverflow.com/q/36055717/7605325 - https://stackoverflow.com/q/44979279/7605325 –
[SimpleDateFormat可能重复的毫秒数不能超过4数字](https://stackoverflow.com/questions/36055717/simpledateformat-cannot-parse-milliseconds-with-more-than-4-digits) –