JPHamlett
2013-01-25 16:16:54
Does anyone know of an easier method to format times than a bunch of if else statements?
What I mean by format for example
[ATTACH]18822[/ATTACH]
That was just a quick job I could care less
Basically I need to get it output a hour variable and a minute variable like such hh:mm
here is my attempt, doesn't work, I have not debugged it thoroughly yet
getHour and getMinute just return a variable assigned to the class
What I mean by format for example
[ATTACH]18822[/ATTACH]
That was just a quick job I could care less
Basically I need to get it output a hour variable and a minute variable like such hh:mm
here is my attempt, doesn't work, I have not debugged it thoroughly yet
@Override
public String toString(){
boolean pm = getHour() > 12;
String min ="" , hour = "";
if (getMinute() < 10){
min = "0" + getMinute();
} else {
min = "" + getMinute();
}
if (getHour() < 10){
hour = "0" + getHour();
}
if (getHour() > 12 && getHour() - 12 < 10){
hour = "0" + (getHour() - 12);
}
if (getHour() > 9 && getHour() < 13){
hour = "" + getHour();
}
if (pm){
return hour + ":" + min + " PM";
}
return hour + ":" + min + " AM";
}
getHour and getMinute just return a variable assigned to the class