-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,132
  • 12
  • 65
  • 109

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
  • 43,525
  • 5
  • 33
  • 63
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
  • 22,588
  • 21
  • 86
  • 152
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,582
  • 11
  • 30