String str = "2017-08-01T15:15:03.313456768+02:00";
// The following statement gives IllegalArgumentExceptionTimestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
Timestamp timeStamp = Timestamp.valueOf(str);
ZonedDateTime zoneddate = ZonedDateTime.parse(str);
System.out.println("ZonedDate: "+zoneddate);// prints 2017-08-01T15:15:03.313456768+02:00
Instant inst = zoneddate.toInstant();
Timestamp newTime = Timestamp.from(inst);
System.out.println("Timestamp: "+newTime);// prints 2017-08-01 15:15:03.313456768 without Zone
我在轉換過程中缺少區域。任何人都可以建議我如何在TimeStamp
獲得Zone?如何將字符串(2017-08-01T15:15:03.313000000 + 02:00)轉換爲時間戳
我是red alredy,但SimpleDateFormat不接受9位毫秒。 – user2814979
請顯示您嘗試過的代碼 – Jens
'SimpleDateFormat'具有毫秒精度(小數點後只有3位數)。對於超過3位數字,您必須使用Java 8新的'java.time' API:https://stackoverflow.com/questions/30135025/java-date-parsing-with-microsecond-or-nanosecond-ccuracy – 2017-08-16 11:51:51