Java: convert seconds into day, hour, minute and seconds using TimeUnit

后端 未结 8 1767
我寻月下人不归
我寻月下人不归 2020-12-08 06:25

I am using TimeStamp class to convert seconds into Day,Hours,Minutes,Seconds. I used following code

public static void calculateTime(long seconds) {
                 


        
8条回答
  •  醉梦人生
    2020-12-08 06:58

    public static void timeCalculator(){
    
    
          Scanner input = new Scanner(System.in);
          System.out.print("Enter length of time in seconds: ");
          int n = input.nextInt();
          int nDay = n/86400;
          int nHours = (n%86400)/3600;
          int nMin = ((n%86400)%3600) /60;
          int nSec =(((n%86400)%3600)%60);
          System.out.println();
          System.out.print("That is "+ nDay+ " day(s),"+nHours+"  hour(s), "+nMin+"  minute(s), and "+nSec+" second(s). ");
    }
    

提交回复
热议问题