[ACCEPTED]-How to convert string to time in android?-time
Accepted answer
Read SimpleDateFormat documentation (parse&format 1 methods and pattern syntax).
http://developer.android.com/reference/java/text/SimpleDateFormat.html
String time = "530pm";
SimpleDateFormat dateFormat = new SimpleDateFormat("hmmaa");
SimpleDateFormat dateFormat2 = new SimpleDateFormat("hh:mm aa");
try {
Date date = dateFormat.parse(time);
String out = dateFormat2.format(date);
Log.e("Time", out);
} catch (ParseException e) {
}
final String NEW_FORMAT = " hh:mm";
final String OLD_FORMAT = "hh:mm:ss";
String formatDate;
SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
Date d = null;
try {
d = sdf.parse(Value);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sdf.applyPattern(NEW_FORMAT);
formatDate=sdf.format(d);
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.