0

Following code

 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yy", new DateFormatSymbols(Locale.US));
        System.out.println(simpleDateFormat.parse("03-Apr-96"));

Gives output as Wed Apr 03 00:00:00 IST 1996

What should I do get the output like 1996-04-03 00:00:00.0

4
  • you also need time or just date? Commented Jan 10, 2013 at 7:59
  • Thanks for replying, I need Date appended with 00:00:00.0 Commented Jan 10, 2013 at 8:00
  • I have added a question at the bottom ,please suggest.I'm sorry for putting my question as an answer Commented Jan 10, 2013 at 11:00
  • Full reference of characters and examples are in SimpleDateFormat javadoc. docs.oracle.com/javase/6/docs/api/java/text/… Commented Jan 10, 2013 at 11:27

3 Answers 3

1

Try the following:

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yy", new DateFormatSymbols(Locale.US));
    Date d = simpleDateFormat.parse("03-Apr-96");  
    simpleDateFormat.applyPattern("yyyy-MM-dd HH:mm:ss.S");
    System.out.println(simpleDateFormat.format(d));
Sign up to request clarification or add additional context in comments.

Comments

0

A DateFormat object can be either used to parse a String into a Date object or the other way around. In your example, you're doing the former, when what you really want to do is to format your Date into a given pattern.

Here's an example of what you may want to do:

DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.print(df.format(yourDateObject));

Comments

0

Try this:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yy", new DateFormatSymbols(Locale.US));
        Date date=simpleDateFormat.parse("03-Apr-96");

        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S", new DateFormatSymbols(Locale.US));
        System.out.println(simpleDateFormat1.format(date));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.