How do I convert a Long time to a video duration ?, Long TYPE

Source: Internet
Author: User

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:

  

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.