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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.