How do I convert a Long time to a video duration ?, Long TYPE
The video duration stored in the database is a Long type of millisecond/second time. Now we need to convert this time to the standard video duration format, in my opinion, this should be a very common conversion method and a very common conversion method tool. However, I have been searching for Baidu for a long time, no simple and intuitive tool class meets my needs. Well, I can't find it better. I will write a tool class for my own use and it will be convenient for your reference!
Import java. util. date; public class VideoTimeUtil {/*** millisecond time * Long type time converted to video duration */public static String format (Long time) {if (time = null) {return null;} else {Date date = new Date (time); long hour = time/(60x60*1000 ); long minute = (time-hour * 60*60*1000)/(60*1000 ); long second = (time-hour * 60*60*1000-minute * 60*1000)/1000; return (hour = 0? "00" :( hour> 10? Hour :( "0" + hour) + ":" + (minute = 0? "00" :( minute> 10? Minute :( "0" + minute) + ":" + (second = 0? "00" :( second> 10? Second :( "0" + second);}/*** time is second * Long type time converted to video duration */public static String formatTime (Long time) {if (time = null) {return null;} else {Date date = new Date (time); long hour = time/(60*60 ); long minute = (time-hour * 60*60)/60; long second = time-hour * 60*60-minute * 60; return (hour = 0? "00" :( hour> 10? Hour :( "0" + hour) + ":" + (minute = 0? "00" :( minute> 10? Minute :( "0" + minute) + ":" + (second = 0? "00" :( second> 10? Second :( "0" + second); public static void main (String args []) {Long time = 6556L; String format = VideoTimeUtil. formatTime (time); System. out. println (format );}}
The output result of the above main method is as follows: