1

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?

fredley
  • 32,953
  • 42
  • 145
  • 236
Chirag
  • 56,621
  • 29
  • 151
  • 198

2 Answers2

2

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);
    }
}
Community
  • 1
  • 1
st0le
  • 33,375
  • 8
  • 89
  • 89
0

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.

Siten
  • 4,515
  • 9
  • 39
  • 64