Click here to Skip to main content
14,928,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am having an edit text where user can enter like ("3 days" or "2 hour" or "5 months")whatever,

It needs to convert it to minutes..
I have no idea , please guide me






Thanks in advance
Arahv.M
Posted
Updated 11-Mar-15 20:08pm
v2

Create a table that maps the descriptions to the number of minutes or seconds. e.g
Day = 1440
Hour = 60
...

Split the string into its component parts.
Get the number of minutes from the conversion table.
Multiply that by the number and that is the number of minutes.
Convert that to whatever format you need for the display.
   
Java
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) {
}



Try this
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900