0
我有時間格式 2015-08-14T06:00:00+08:00
的字符串,我想將其轉換爲TIMESTAMP但:轉換時間字符串轉換爲時間標記的Java
public static Long convertTimeStringToTimeStampMilSec(String timeStr){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-ddTHH:MM:SS+08:00");
try {
Date d = dateFormat.parse(timeStr);
Calendar c = Calendar.getInstance();
c.setTime(d);
return c.getTimeInMillis();
}catch (Exception e){
e.printStackTrace();
return null;
}
}
並獲得例外:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'T'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:845)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:659)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:585)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:560)
如何處理這個?
http://stackoverflow.com/a/2597111/3166303 – leeor