I'm having a problem with Date Parsing.
I am getting dates from JXDatePicker and need to re-format them in order to send a query to MySQL.
the date I get from JXDatePicker is in the following format:
Mon Oct 06 00:00:00 IDT 2014
I use this simpledateformat to parse it :
SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
I Also Tried:
SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
And:
SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");
95% of the time its works fine when I run it on eclipse, sometimes I get the parse error (Listed Below), but when I restart my app its working just fine on the same dates and same input.
But, when I compiled my app to a runnable jar in order to really start using it, I get the following error 100% of the times:
java.text.ParseException: Unparseable date: "Mon Oct 06 00:00:00 IDT 2014"
at java.text.DateFormat.parse(Unknown Source)
at DatePicker.findRequests(DatePicker.java:385)
it's driving me crazy !!!
anyone has an idea for me?
I suspect its somehow connected to the TimeZone.
thanks,
Dave.
Don't parse the result from JXDatePicker
at all. It allows you to get the value directly as a java.util.Date
(and time zone).
Wherever possible, avoid converting to/from text. In this case, there's no need for text anywhere - you can get the data out of JXDatePicker
in a "native" format, and you should do the same when specifying the value for MySQL - use a prepared statement with parameterized SQL and call setDate
or setTimestamp
to specify the values.