I am currently trying to write a method that takes a string like "1pm" and converts it to military time --> 13
Right now I have the following and it is not working correctly. Any tips would be greatly appreciated.
/** * Set the hour of this appointment, using a more human-friendly * string. * @param newHour The new hour for this appointment, using an * am/pm designation such as "9am" or "5pm". */
public void setTime(String newHour)
{
String day = newHour.substring(newHour.length() - 2);
String dig = newHour.substring(2, newHour.length() - 2);
if (dig.equals("12"))
{
dig = "0";
}
if (day.equals("am"))
{
hour = Integer.parseInt(dig);
}
else
{
hour = Integer.parseInt(dig) + 12;
}
}