Java format hour and min

后端 未结 4 1321
梦毁少年i
梦毁少年i 2020-12-11 09:36

I need to format my time string such as this:

int time = 160;

Here\'s my sample code:

public static String formatDuration(         


        
4条回答
  •  清歌不尽
    2020-12-11 10:25

    Another simple approach could be something along the lines:

    public static String formatDuration(String minute){
        int minutes = Integer.parseInt(minute);
    
        int hours = minutes / 60;
        minutes = minutes % 60;
    
        return hours + "hrs " + minutes + "mins.";
    }
    

提交回复
热议问题