Board logo

標題: Unparsable Date for Java [打印本頁]

作者: luckiejacky    時間: 2013-8-25 17:03     標題: Unparsable Date for Java

本帖最後由 luckiejacky 於 2013-8-25 17:30 編輯

java.text.ParseException: Unparseable date: "Tue Aug 27 00:00:00 CST 2013"
  1. SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd hh:mm:ss Z yyyy");
  2. System.out.println("Date was " + tblSalesDetail.getValueAt(i,3).toString());
  3. sdf.setTimeZone(TimeZone.getTimeZone("Asia/Hong_Kong"));
  4. java.util.Date result = sdf.parse(tblSalesDetail.getValueAt(i,3).toString().trim()); <<<<<< Here
  5. java.sql.Date sqlDate = new java.sql.Date(result.getTime());
複製代碼
Any ideas why?
Hunting for solutions for hours...

update: solved by using joda time


THX
作者: snoopy11hk    時間: 2013-8-25 17:24

本帖最後由 snoopy11hk 於 2013-8-25 17:26 編輯
java.text.ParseException: Unparseable date: "Tue Aug 27 00:00:00 CST 2013"Any ideas why?
Hunting for ...
luckiejacky 發表於 2013-8-25 17:03



z        Time zone        General time zone        Pacific Standard Time; PST; GMT-08:00
Z        Time zone        RFC 822 time zone        -0800

H        Hour in day (0-23)        Number        0
h        Hour in am/pm (1-12)        Number        12

quote from http://docs.oracle.com/javase/1. ... ateFormat.html#text
作者: luckiejacky    時間: 2013-8-25 17:31

z        Time zone        General time zone        Pacific Standard Time; PST; GMT-08:00
Z        Time zone        RFC 822 time zone ...
snoopy11hk 發表於 2013-8-25 17:24


Thanks snoopy
I was doing
  1. DateTime dt = new DateTime(tblSalesDetail.getValueAt(i,3));
  2. java.sql.Date result = new java.sql.Date(dt.toDate().getTime());
複製代碼
Then it was it.
Jack





歡迎光臨 電腦領域 HKEPC Hardware (https://h0.hkepc.com/forum/) Powered by Discuz! 7.2