views:

155

answers:

2

Hi,

I am trying to convert string to date, but getting error.

I am getting date using :

URL xmlUrl = new URL(path);
URLConnection urlconn = xmlUrl.openConnection();
Date =  new Date(urlconn.getLastModified());

and then I ma saving this date in a file , which saves in the following format :

Mon Jun 21 16:31:24 Asia/Karachi 2010

and then when later I read this date from file as a String, I again want to save it to a Date, but I am getting error.

I tried :

DateFormat format = DateFormat.getDateInstance();
date =  format.parse(fileDate);

but I am getting error :

java.text.ParseException: Unparseable date: Mon Jun 21 16:31:24 Asia/Karachi 2010

Is there any way i can retrieve back the date.

Thanks

+1  A: 

Try this. Have to specify the correct date format.

SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
Date d = format.parse(fileDate);
BrennaSoft
A: 

I had this problem already. check this reto meier's answer posted to me. hope it helps.

Praveen Chandrasekaran