I'm trying to convert Dates into Unix Timestamps in Java. Examples for my dates are: "Fri Jun 05 15:53:07 PDT 2009"
My code is:
DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
Date date = dateFormat.parse(dateString );
long unixTime = (long) date.getTime()/1000;
System.out.println("Unix Time: " + unixTime );
double unixFloat = unixTime;
The given error is:
Exception in thread "main" java.text.ParseException: Unparseable date: "Fri Jun 05 15:53:07 PDT 2009"
What's the right Pattern?
You need to set
Locale
, Some cases if you are not set the locale you may face this kind of issues.Eg:
From
Java
doc.This is probably a Locale issue -
Fri
is friday in English but not in French or German for example: