I retrieved date time from the database and kept it into a ArrayList<String>
type variable. Now I want to format this string.So I need to make a date object firstly. But some problems occurred when I making date object. Following is my code.
Date date = new Date(bookingTime.get(i));
Here bookingTime
is the ArrayList
. Can anyone suggest me what is wrong..
Here is the answer...
String date = "2014-11-25 14:30";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd HH:MM");
Date testDate = null;
try {
testDate = sdf.parse(date);
}catch(Exception ex){
ex.printStackTrace();
}
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd,yyyy hh:mm a");
String newFormat = formatter.format(testDate);
System.out.println(".....Date..."+newFormat);