如何对短视频源码的时间戳进行格式化

短视频源码中时间戳格式化的操作如下
–> 24小时制

SimpleDateFormat sdFormat2 = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);

–>12小时制
SimpleDateFormat sdFormat = new SimpleDateFormat(“请将手机时间与网络同步,时间要精准yyyy-MM-dd hh:mm:ss”);

/* 
     * 将时间转换为时间戳
     */    
    public static String dateToStamp(String s) throws ParseException{
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime();
        res = String.valueOf(ts);
        return res;
    }
/* 
     * 将时间戳转换为时间
     */
    public static String stampToDate(String s){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long lt = new Long(s);
        Date date = new Date(lt);
        res = simpleDateFormat.format(date);
        return res;
    }
发布了150 篇原创文章 · 获赞 65 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/yb1314111/article/details/105244355
今日推荐