-1

I have a timestamp which I have retrieved from database.
For ex:

Timestamp acceptedDate = 2014-10-27 13:39:50; 

Now I want to get time part of the timestamp in a different variable and date part of the timestamp in a different variable and also the time should be a 12 hour clock. How can achieve this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Uday Khatry
  • 449
  • 1
  • 8
  • 23
  • try with Simpledatefromat http://www.mkyong.com/java/java-date-and-calendar-examples/ http://java67.blogspot.in/2013/01/how-to-format-date-in-java-simpledateformat-example.html – Shriram Nov 25 '14 at 06:06
  • check this out. http://stackoverflow.com/questions/7492423/how-can-i-convert-a-timestamp-into-either-date-or-datetime-object – Aditya Nov 25 '14 at 06:06
  • possible duplicate of [Java string to date conversion](http://stackoverflow.com/questions/4216745/java-string-to-date-conversion) – Basil Bourque Nov 25 '14 at 06:49
  • Please search StackOverflow before posting. – Basil Bourque Nov 25 '14 at 06:49

1 Answers1

0

Split to get date and time...

String date = acceptedDate.toString().split(" ")[0];
String time = acceptedDate.toString().split(" ")[1];

Convert 24 hr to 12 hr format...

DateFormat f1 = new SimpleDateFormat("hh:mm:ss");
Date d = f1.parse(time);
DateFormat f2 = new SimpleDateFormat("h:mma");
f2.format(d).toLowerCase();
time = f2.toString();

I hope this helps... :)

Salmaan
  • 3,543
  • 8
  • 33
  • 59