Как изменить военное время на десятичное?

У меня есть небольшая проблема здесь с getDecimalTime метод. Я не знаю, есть ли какая-нибудь формула, которая поможет мне изменить военное время (например, 0645 -> 06:04) на десятичное время.

public class TimeInterval
{
   int time1;
   int time2;
   int hours;
   int minutes;
   double decTime;
   public TimeInterval()
   {
      time1 = 0;
      time2 = 0;
   }
   public TimeInterval(int _time1, int _time2)
   {
      time1 = _time1;
      time2 = _time2;
   }

   public int getHours()
   {

      if(time1 > time2)
      {
         hours = (time1 - time2) / 100;
      }
      else if(time1 < time2)
      {
         hours = (time2 - time1) / 100;
      } 
      return hours;
   }

   public int getMinutes()
   {
      if(time1 > time2)
      {
         minutes = (time1 - time2) % 100;
      }
      else if(time1 < time2)
      {
         minutes = (time2 - time1) % 100;
      } 
      return minutes;
   }
   public double getDecimalTime()
   {
      return decTime;
   }
}

тестер:

import java.util.*;

public class TestTimeInterval
{
   public static void main(String[] args)
   {

      Scanner in = new Scanner(System.in);

      System.out.println("Please enter the first time: ");
      int _time1 = in.nextInt();

      System.out.println("Please enter the second time: ");
      int _time2 = in.nextInt();

      TimeInterval object = new TimeInterval(_time1,_time2);

      System.out.println("Elapsed time in hrs/min: " + object.getHours() + " hours " + object.getMinutes() + " minutes");
      System.out.println("Elapsed time in decimal: " + object.getDecimalTime() + " hours");


   }
}

0 ответов

Другие вопросы по тегам