tags:

views:

39

answers:

1

Hi,

I am receiving last modification date of a file, using below code :

xmlUrl = new URL("http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html");
URLConnection urlconn = xmlUrl.openConnection();
urlDate =  new Date(urlconn.getLastModified());

In result I am getting date in below format:

Tue Dec 18 05:11:33 Asia/Karachi 2007

I want to change it to simple dd MMM yyyy format

I used :

SimpleDateFormat format = new SimpleDateFormat("dd MMM yyyy");
try {
        tempDate = format.parse(urlDate.toString());

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

but it didn't help me to solve the issue and I am still getting the date in that above mentioned long format.

need urgent help.

Thanks

+5  A: 
tempDate = format.parse(urlDate.toString());

That's backwards and should lead to an exception. A DateFormat is for converting between String and Date both ways, and the format string must always match the pattern of the String side.

What you want is this:

tempDate = format.format(urlDate);
Michael Borgwardt
tempDate = format.format(urlDate)is not working, as format(Date) method, returns a string and tempDate is a Date type variable.what I did createdDateFormat format = DateFormat.getDateInstance(DateFormat.FULL);tempDate = format.format(urlDate);even I tried to cast it but no use :(
kaibuki
@kaibuki: a Date does not *have* a format, it's always a timestamp with millisecond precision. If you want to display it in a specific format, that means turning it into a String.
Michael Borgwardt