-1

I have a date in the format 11-NOV-13 When i convert the date i get the value Sat Nov 11 00:00:00 IST 13. But i want the converted date to be in the format Sat Nov 11 00:00:00 IST 2013. Though i have used the dateformat it is not taking it. Can anyone point me where i am wrong?

Below is the code i have been working on

DateFormat format = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
Date myDate = format.parse("11-NOV-13");
sTg
  • 4,313
  • 16
  • 68
  • 115

4 Answers4

2

Change the format to:

DateFormat format = new SimpleDateFormat("dd-MMM-yy", Locale.ENGLISH);
1

As you are not providing the full year you need

    DateFormat format = new SimpleDateFormat("dd-MMM-yy", Locale.ENGLISH);
    Date myDate = format.parse("11-NOV-13");

    System.out.println(myDate);
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
1

You need to make the year 2 numbers:

DateFormat format = new SimpleDateFormat("dd-MMM-yy", Locale.ENGLISH);

You can reference the docs here.

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
0

Change to this format:

SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
DateFormat format = new SimpleDateFormat("dd-MMM-yy", Locale.ENGLISH);
Date myDate = format.parse("11-NOV-13");

String formattedDate = sdf.format(myDate);
Vygintas B
  • 1,624
  • 13
  • 31