I have a time string like 4:52 pm. I want to convert it in milliseconds for comparison with current time of system. How is it possible in android ?
Asked
Active
Viewed 499 times
-11
-
Easy ton find on google ... – Drakkin May 13 '15 at 13:05
-
You should really learn googleing and reading APIs.... – Opiatefuchs May 13 '15 at 13:07
2 Answers
3
long millis = 0;
DateFormat dateFormat = new SimpleDateFormat("hh:mm a");
try {
Date d = dateFormat.parse("4:52 PM");
millis = d.getTime();
} catch (ParseException e) {
e.printStackTrace();
}

Bojan Kseneman
- 15,488
- 2
- 54
- 59
-1
String someTime = "4:52 pm";
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm aa");
Date date = sdf.parse(someTime);
System.out.println(date.getTime());

Sunil
- 482
- 6
- 12