-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
  • 34,719
  • 24
  • 185
  • 251
Uday Khatry
  • 439
  • 1
  • 6
  • 21

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,648
  • 8
  • 33
  • 59