时间转化工具类,将mm转换为hh:mm:ss

1.时间转化工具类,将mm转换为hh:mm:ss

背景:在Android播放器中,获取到的视频或音频资源的时长是mm显示的,为直观展示,需要进行转化。

工具类:

package com.example.checkbugs.Utils;

import java.text.SimpleDateFormat;
import java.util.Formatter;

/**
 * 转换视频时长:mm -时:分:秒
 */
public class VideoDurationTools {

    public static String transfMMtoNarmal(long mmTime){
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");//初始化Formatter的转换格式。
        String hms = formatter.format(mmTime);
        return hms;
    }


    public static String mm2hsm(long mmTime){

        //1.小时
        //sec=1000ms
        //min = 60sec
        //hour = 60min
        int  h = (int) (mmTime / (60*60*1000));
        int min = (int) (mmTime%(60*60*1000) /(60*1000));
        int sec = (int) ((mmTime%(60*60*1000) % (60*1000))/1000);

        Formatter formatter = new Formatter();
        String result = formatter.format("%02d:%02d:%02d", h, min, sec).toString();
        return  result;
    }




}

调用:

        int duration = video_view_player.getDuration();
        int currentPosition = video_view_player.getCurrentPosition();

        String curTime = VideoDurationTools.mm2hsm((long) currentPosition);

        String durTime = VideoDurationTools.mm2hsm((long)duration);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值