天天看點

java.util.date的格式,在java中将字元串轉換為java.util.date格式

java.util.date的格式,在java中将字元串轉換為java.util.date格式

am having a string like this.

Thu Oct 07 11:31:50 IST 2010

I want to convert this into its exact date time format to store it in SQL.

Am familiar with so many string to date conversions like the following.

String dateString = "2001/03/09";

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/mm/dd");

Date convertedDate = dateFormat.parse(dateString);

But i need to convert a string like Thu Oct 07 11:31:50 IST 2010

into its Date format with timestamp.

Can anyone explain the proper way of converting this into its java.util.Date format.?

解決方案

Try this:

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