将整数分钟转换为字符串“hh:mm” [英] Convert integer minutes into String "hh:mm"

查看:177
本文介绍了将整数分钟转换为字符串“hh:mm”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 minutes (定义为Integer)转换为以下字符串格式hh:mm,假设 startTime 是00:00。下面给出的代码是我目前所拥有的,但它无法正常工作。此外,它没有考虑 newTime 应根据 startTime 进行转移。还有其他解决方案吗?

I need to convert minutes (defined as Integer) into the following String format "hh:mm" assuming that the startTime is "00:00". The below-given code is what I have so far, but it does not work properly. Also it does not take into account that the newTime should be shifted in accordance to startTime. Is there any other solution?

String startTime = "00:00";
int minutes = 120;
double time = minutes/60;
String timeS = Double.toString(time);
String[] hourMin = timeS.split(".");
String h = hourMin[0];
String m = hourMin[1];
String newTime = "";    
newTime.concat(h+":"+m);


推荐答案

String startTime = "00:00";
int minutes = 120;
int h = minutes / 60 + Integer.parseInt(startTime.substring(0,1));
int m = minutes % 60 + Integer.parseInt(startTime.substring(3,4));
String newtime = h+":"+m;

这篇关于将整数分钟转换为字符串“hh:mm”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆