-6

Using java I need to parse this 2014-08-31 13:53:42.0 to 31-AUG-14 01.53.42 PM

Burkhard
  • 14,401
  • 22
  • 87
  • 107

1 Answers1

5

Start by doing some research into java.text.SimpleDateFormat which can be used to parse String values of a verity of formats into a java.util.Date.

You can then use another SimpleDateFormat to format the value to the format that you want, for example

try {
    String in = "2014-08-31 13:53:42.0";
    SimpleDateFormat sdfIn = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
    Date date = sdfIn.parse(in);
    System.out.println(date);
    SimpleDateFormat sdfOut = new SimpleDateFormat("dd-MMM-yy hh:mm.ss a");
    System.out.println(sdfOut.format(date));
} catch (ParseException ex) {
}

Which outputs

Sun Aug 31 13:53:42 EST 2014
31-Aug-14 01:53.42 PM
MadProgrammer
  • 336,120
  • 22
  • 219
  • 344
  • I think it's better if we don't provide full solutions for question like that. – Maroun Sep 01 '14 at 07:33
  • @MarounMaroun If you can find a duplicate, please tell me and I'll delete the answer and close the question – MadProgrammer Sep 01 '14 at 07:35
  • Your answer is good since it contains explanation and not only code, it's detailed one, +1. But I think that OP might always think that he shouldn't do research and ask questions here with minimal understanding. – Maroun Sep 01 '14 at 07:36
  • @MarounMaroun I'd prefer more research as well, it's a common problem with a common solution ;) - But teaching myself Objective C at the moment, what might seem simple to your mean, isn't always that simple for other people. That's when I search SO ;) – MadProgrammer Sep 01 '14 at 07:38
  • @MarounMaroun What you say is true but Stackoverflow is meant to provide answer to coding queries asked by users, if a user asks his homework or anything else without research its his loss. Maybe this user did a lot of research and could not find solution, or maybe he didn't. If we start assuming many questions may remain unanswered. +1 for the answer BTW – Mustafa sabir Sep 01 '14 at 07:41
  • this is good answer. – Fevly Pallar Sep 01 '14 at 12:06