i'm using JXDatePicker and JSpinner to input date and time from the user.
I then need to format it back to one date in a long millisecond format.
with input of 03/09/2014 in JXDatePicker , the output from the JXDatePicker is:
Wed Sep 03 00:00:00 IDT 2014
and with input of 11:00 in JSpinner, the output from JSpinner is :
Thu Jan 01 22:33:00 IST 1970
I need to combine both this outputs to get the full date , and then convert it to a long in millis.
I use this code:
SimpleDateFormat f = new SimpleDateFormat("DDD MMM dd yyyy hh:mm:ss");
String string_date =
datePicker.getDate().toString().substring(0, 11) +
datePicker.getDate).toString().substring(24, 28) +
hourPicker.getValue().toString().substring(10,19);
Date d;
try {
d = f.parse(string_date);
} catch (ParseException e3) {
e3.printStackTrace();
}
and get this exception:
java.text.ParseException: Unparseable date: "Wed Sep 17 2014 12:44:22"
at java.text.DateFormat.parse(Unknown Source)
at MainFrame.sendButtonActionPerformed(MainFrame.java:598)
at MainFrame.access$3(MainFrame.java:574)
at MainFrame$3.actionPerformed(MainFrame.java:434)
please help !
thanks, Dave.
In order to parse Wed use 'EEE' like show below, list of valid flags are here
class Test
{
public static void main(String[] args) throws ParseException {
SimpleDateFormat f = new SimpleDateFormat("EEE MMM dd yyyy hh:mm:ss");
String string_date = "Wed Sep 17 2014 12:44:22";
System.out.println(f.parse(string_date));
}
}