快速提问。
是否有更智能/更时尚的方法将分钟转换为更易读的格式,只显示最重要的数字?
我正在使用 Android Studio 的 Java。
public String MinutesToHumanReadable(Long minutes) {
...
}
IE
2 mins = "2 mins"
45 mins = "45 mins"
60 mins = ">1 hr"
85 mins = ">1 hr"
120 mins = ">2 hrs"
200 mins = ">3 hrs"
1500 mins = ">1 day"
我的代码非常繁琐、草率,而且有些不可读。
public String MinutesToHumanReadable(long minutes) {
String sReturn = "";
if (minutes > 515600) {
sReturn = "> 1 yr";
} else if (minutes > 43200) {
sReturn = (minutes / 43200) + " mths";
} else if (minutes > 10080) {
sReturn = (minutes / 10080) + " wks";
} else if (minutes > 1440) {
sReturn = (minutes / 1440) + " days";
} else if (minutes > 60) {
sReturn = (minutes / 60) + " hrs";
} else {
//<60
sReturn = minutes + " mins";
}
return sReturn;
}
非常感谢,J