Java format hour and min

后端 未结 4 1294
梦毁少年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:21

    int minutes = 160;
    
    int h = minutes / 60;
    int m = minutes % 60;
    
    String.format("%d hr %d mins",h,m); // output : 2 hr 40 mins
    

提交回复
热议问题