JavaSE-时间差
2022/7/28 1:24:02
本文主要是介绍JavaSE-时间差,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
public static String getDiffDateStr(Date startTime,Date endTime){ long diff = endTime.getTime() - startTime.getTime(); long diffSeconds = diff / 1000 % 60; long diffMinutes = diff / (60 * 1000) % 60; long diffHours = diff / (60 * 60 * 1000) % 24; long diffDays = diff / (24 * 60 * 60 * 1000); String diffTimeStr = ""; if (0 != diffDays) { diffTimeStr = diffTimeStr + diffDays + "天"; } if (0 != diffHours) { diffTimeStr = diffTimeStr + diffHours + "小时"; } if (0 != diffMinutes) { diffTimeStr = diffTimeStr + diffMinutes + "分钟"; } if (0 != diffSeconds) { diffTimeStr = diffTimeStr + diffSeconds + "秒"; } return diffTimeStr; }
这篇关于JavaSE-时间差的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23JAVA语音识别项目入门教程
- 2024-11-23Java云原生学习:从入门到实践
- 2024-11-22Java创业学习:初学者的全面指南
- 2024-11-22JAVA创业学习:零基础入门到实战应用教程
- 2024-11-22Java创业学习:从零开始的Java编程入门教程
- 2024-11-22Java对接阿里云智能语音服务学习教程
- 2024-11-22JAVA对接阿里云智能语音服务学习教程
- 2024-11-22Java对接阿里云智能语音服务学习教程
- 2024-11-22Java副业学习:零基础入门到实战项目
- 2024-11-22Java副业学习:零基础入门指南