mercredi 23 avril 2014

Passing always two characters to string from an int value


Vote count:

0




This is the piece of code i am using to extract:


-day of week


-day of month


-month


-year


-hour


-minutes


from a string



//calculo de fechas

String fecha = resultp.get(Agenda_MainActivity.DIA);//format->2014-04-21
String time = resultp.get(Agenda_MainActivity.HORA);//format -> 17:30:00
String string = fecha+" "+time;


Calendar calender = Calendar.getInstance();
try {
calender.setTime(new SimpleDateFormat("yyyy-MM-d k:m:s").parse(string));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


All is working fine. The only issue I have is calculating the minutes. This is the code I use to extract the minutes:



String Minutos = String.valueOf(calender.get(Calendar.MINUTE));


The problem is the following, if the time is 17:35, then Minutos = "35", as it should be. But is the time is like 17:00, then Minutos = "0", and not "00".


I need your help to solve this small issue. Thank you.



asked 10 secs ago

mvasco

457





Aucun commentaire:

Enregistrer un commentaire