-11

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 ?

akash
  • 22,664
  • 11
  • 59
  • 87
Zeeshan Ali
  • 2,211
  • 4
  • 18
  • 25

2 Answers2

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