Reputation: 56935
I have dates in the format:
Wed Jan 18 08:50:04 Asia/Calcutta 2012
I want to depict just 18.01.2012
, how do I do this?
Upvotes: 1
Views: 93
Reputation: 4533
Try in your code:
SimpleDateFormat sdfDate = new SimpleDateFormat("dd.MM.yyyy");
java.util.Date date = new java.util.Date();
String strDate = sdfDate.format(date);
I tried that.
Upvotes: 0
Reputation: 33565
A Bit hacky because of the Asia/Calcultta
EDIT: Also found this
public class Foo {
public static void main(String[] args) throws Exception {
String date = "Wed Jan 18 08:50:04 Asia/Calcutta 2012";
System.out.println(formatDate(date));
}
private static String formatDate(String date) throws Exception {
String year = date.substring(date.lastIndexOf(' ') + 1);
DateFormat sdf = new SimpleDateFormat("EEE MMM dd kk:mm:ss");
SimpleDateFormat fmt = new SimpleDateFormat(String.format("dd.MM.%s",
year));
Date parse = sdf.parse(date);
return fmt.format(parse);
}
}
Upvotes: 2