This discussion is archived
4 Replies Latest reply: Jun 7, 2013 8:29 AM by doremifasollatido RSS

Java date format

user11237452 Newbie
Currently Being Moderated
Hi everyone,

I have a piece of code as below for date format conversion.
DateFormat formatter1 ; 
DateFormat formatter2 ; 
Date date = new Date(); 

formatter1 = new SimpleDateFormat("yyyy-mm-dd");
date = formatter1.parse("1952-12-10"); 
System.out.println("before format, date is " + date);

formatter2 = new SimpleDateFormat("dd-MMM-yy");
formatter2.format(date);
System.out.println("after format, date is " +formatter2.format(date));
I would like to change 1952-12-10 become 10-DEC-52, however, I am getting below output:

before format, date is Thu Jan 10 00:12:00 MYT 1952
after format, date is 10-Jan-52

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points