I'd like to write two methods which both rely on the information on how much time is left in the day (how many seconds there are left till the end of the day, as well as how much percent of the day already have passed). Different days have a different span of (sometimes just) seconds and sometimes hours so it won't work for me to just count on 24 * 60 * 60 and subtract the result of sinceMidnight(). I tried to add a day to the current time, yet till now I failed.
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
public class TimesOfSeconds {
public static void sinceMidnight(int intHours, int intMinutes, int intSeconds) {
int hoursInSeconds = intHours * 60 * 60;
int minutesInSeconds = intMinutes * 60;
int secondsSinceMidnight = hoursInSeconds + minutesInSeconds + intSeconds;
System.out.println(secondsSinceMidnight + " Seconds since Midnight!");
}
public static void tillEndOfDay() {
}
public static void percentOfDayPassed() {
}
public static void getTheTimeRight(int intHours, int intMinutes, int intSeconds) {
System.out.println(intHours + " " + intMinutes + " " + intSeconds);
}
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat justHours = new SimpleDateFormat("HH");
int intHours = Integer.parseInt(justHours.format(cal.getTime()));
SimpleDateFormat justMinutes = new SimpleDateFormat("mm");
int intMinutes = Integer.parseInt(justMinutes.format(cal.getTime()));
SimpleDateFormat justSeconds = new SimpleDateFormat("ss");
int intSeconds = Integer.parseInt(justSeconds.format(cal.getTime()));
getTheTimeRight(intHours, intMinutes, intSeconds);
sinceMidnight(intHours, intMinutes, intSeconds);
}
}