Long類型時間如何轉換成視頻時間長度?,long類型

來源:互聯網
上載者:User

Long類型時間如何轉換成視頻時間長度?,long類型

  資料庫中存放的視頻時間長度是一個Long類型的毫秒/秒時間,現在需要把這個時間轉換成標準的視頻時間長度格式,在我看來這應該是一個很常用的轉化有一個很常用的轉換方法工具才對,可是我百度找了許久,沒有一個簡單直觀的工具類剛好滿足我的需求,好吧,找不到更好,那我自己寫一個工具類自己用,同時也方便以後大家需要,供大家參考參考!

  

import java.util.Date;public class VideoTimeUtil {    /**     * 毫秒時間     * Long類型時間轉換成視頻時間長度     */    public static String format(Long time){        if(time == null){            return null;        }else{            Date date = new Date(time);            long hour = time/(60*60*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)));        }    }    /**     * 時間為秒     * Long類型時間轉換成視頻時間長度     */    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);    }}

 

  以上main方法輸出結果如下:

  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.