JAVA实现秒转换为时分秒格式
【摘要】
查询到的方法:
public static String secToTime(int seconds) {
int hour = seconds / 3600;
int...
查询到的方法:
public static String secToTime(int seconds) {
int hour = seconds / 3600;
int minute = (seconds - hour * 3600) / 60;
int second = (seconds - hour * 3600 - minute * 60);
StringBuffer sb = new StringBuffer();
if (hour > 0) {
sb.append(hour + "小时");
}
if (minute > 0) {
sb.append(minute + "分");
}
if (second > 0) {
sb.append(second + "秒");
}
if (second == 0) {
sb.append("<1秒");
}
return sb.toString();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
实际在项目中使用的:
public ItooResult selectKeyByTimeClass(Date createTime, Date endTime, String className) {
List<KeyModel> keyModels = KeyDao.selectKeyByTimeClass(createTime, endTime, className);
if (keyModels == null || keyModels.size() == 0) {
return new ItooResult(ItooResult.FAIL, "查询失败");
}
//将time类型的练习时长转换为*分*秒的字符串类型
for (KeyModel keyModel : keyModels) {
Integer setTime = keyModel.getSetTime();
Integer minute=setTime/60;
Integer second=(setTime-minute*60);
StringBuffer sb = new StringBuffer();
if (minute > 0) {
sb.append(minute + "分");
}
if (second > 0) {
sb.append(second + "秒");
}
String strDate = sb.toString();
keyModel.setStrTime(strDate);
}
return new ItooResult(ItooResult.SUCCESS, "查询成功", keyModels);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
文章来源: blog.csdn.net,作者:张艳伟_Laura,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/Laura__zhang/article/details/120624835
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)