时间秒转换成时分秒

时间秒转换成时分秒
1.数据库可以把时间差变成秒
语句为

SELECT
	//把时间差变成秒, TIMESTAMPDIFF(参数1,开始时间,结束时间)
	//参数1:DAY(天),HOUR(小时),MINUTE(分钟),SECOND(秒)
      	SELECT TIMESTAMPDIFF(SECOND,'2018-11-26 15:55:28','2018-11-26 16:09:22');
        结果:
        834秒

2.java转换秒工具类

参数:Integer seconds(传入需要转换成小时分钟秒的数值)
 public String getTime(Integer seconds){
        Integer temp=0;
        StringBuffer time=new StringBuffer();
        temp = seconds/3600;
        time.append((temp<10)?temp+"小时":temp+"小时");

        temp=seconds%3600/60;
        time.append((temp<10)?temp+"分钟":temp+"分钟");

        temp=seconds%3600%60;
        time.append((temp<10)?temp+"秒":temp+"秒");
        return time.toString();
    }
    结果:
    0小时13分钟54秒

以上就可以把秒换算成时分秒格式

猜你喜欢

转载自blog.csdn.net/ip15988/article/details/84581098