user2413387
user2413387

Reputation: 37

Java parsing String date to MilliSecond

How do I convert date string 'Fri Mar 14 09:44:31 IST 2014' to millisec?

I tried with this Java code:

String dateStr = "Fri Mar 14 09:44:31 IST 2014";
SimpleDateFormat sdf = new SimpleDateFormat("MM dd HH:MM:ss");
try {
    System.out.println(sdf.parse(dateStr).getTime());
} catch (ParseException e) {
    e.printStackTrace();
}

Upvotes: 1

Views: 177

Answers (2)

Arjit
Arjit

Reputation: 3456

your SimpleDateFormat is not correct.

Try this

SimpleDateFormat sd = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");

Upvotes: 2

Jaemok Lee
Jaemok Lee

Reputation: 167

try following code.

SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US);

Upvotes: 1

Related Questions