當我運行下面的代碼將時間字符串轉換爲Java日期時,它失敗。如何在Java中使用偏移時間簡單日期格式
String s = "04/17/2017 06:46:53 -600";
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss Z");
Date value = format.parse(s);
Exception in thread "main" java.text.ParseException: Unparseable date: "04/17/2017 06:46:53 -600"
at java.text.DateFormat.parse(Unknown Source)
什麼是用於將日期字符串轉換爲java日期的正確格式字符串?
可能需要'-0600'不'-600' – AxelH
https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html#rfc822timezone – 1615903
請參閱http:// stackoverflow.com/questions/9541043/java-convert-string-to-date-in-with-time-zone-variable?rq=1 – 2017-04-20 11:48:15