0

Using SimpleDateFormat:

DateFormat df = new SimpleDateFormat("dd-MMMM-YYYY kk:mm:ss.SSS");
Date extractedDate = df.parse(possibleDate);

Input given:

11-May-2017 21:45:33.614

Output data object:

Sun Jan 01 21:45:33 MST 2017

I have tried lots of iterations but it won't pull the month and day.

Ashraful Islam
  • 12,470
  • 3
  • 32
  • 53
Jeff Idol
  • 11
  • 1
  • 1

1 Answers1

4

Use dd-MMM-yyyy kk:mm:ss.SSS as pattern

Example :

DateFormat df = new SimpleDateFormat("dd-MMM-yyyy kk:mm:ss.SSS");
Date extractedDate = df.parse("11-May-2017 21:45:33.614");
System.out.println(extractedDate);

Output :

Thu May 11 21:45:33 BDT 2017

Another thing If you use kk for hour, hour should be represent between 1 to 24. If the hour between 0 to 23 use HH instead of kk

Ashraful Islam
  • 12,470
  • 3
  • 32
  • 53