Harinder
Harinder

Reputation: 11944

change value of a timestamp format into other timestamp format?

Hi can anyone tell me how can i change a given timestamp format into other timestamp format like

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Calendar d1 = Calendar.getInstance();
d1.setTime(formatter.parse("2012-03-08 17:32:56"));

to

"dd-MMM-yyyy HH:mm:ss"

format

Upvotes: 1

Views: 6063

Answers (2)

Subhrajyoti Majumder
Subhrajyoti Majumder

Reputation: 41210

format the date with new date format dd-MMM-yyyy HH:mm:ss

   DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   Date oldFormatedDate = formatter.parse("2012-03-08 17:32:56");
   System.out.println(new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss").
   format(oldFormatedDate));

Upvotes: 3

MByD
MByD

Reputation: 137382

Continue with DateFormat#format(Date):

SimpleDateFormatter newFormat = new SimpleDateFormatter("dd-MMM-yyyy HH:mm:ss");
String newFormattedDate = newFormat.format(d1);

Upvotes: 0

Related Questions