Reputation: 17340
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.
Upvotes: 0
Views: 395
Reputation: 346347
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);
Upvotes: 5