I want to convert this date "Sat, 16 Nov 2013 20:09:07"
to unixtime
my code
SimpleDateFormat pattern = new SimpleDateFormat("EEE, dd MM yyyy HH:mm:ss");
Date date = pattern.parse("Sat, 16 Nov 2013 20:09:07")
long milliseconds = date.getTime();
i got this exception
java.text.ParseException: Unparseable date: "Sat, 16 Nov 2013 20:09:07"
(at offset 8)
at java.text.DateFormat.parse(DateFormat.java:555)
is there a problem with the pattern ??
Yes - you're using MM
which is a numeric month pattern. You want MMM
instead, as that's "abbreviated month name". I'd also suggest explicitly specifying Locale.US
in the SimpleDateFormat
constructor if you know that the month and day names will be in English (otherwise it'll use the system default locale).
See more on this question at Stackoverflow