JAVA (Spring Boot) 时间戳转时间

/**
     * 将时间戳转换为时间
     * @param s  时间戳
     * @param t  时间
     * @return
     */
    public static String stampToDate(int s,String t){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(t);
        Date date = new Date((long) s*1000);
        res = simpleDateFormat.format(date);
        return res;
    }

    public static int dateToStampT(String s,String t) throws ParseException {
        //设置时间模版
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(t);
        Date date = simpleDateFormat.parse(s);
        long l = date.getTime();
        return (int) (l / 1000);
        //res = String.valueOf(ts);

    }

 

 注: 时间搓 10位时间戳  所以要乘1000 ; 时间戳 13位 则是除1000

posted @ 2023-03-08 15:16  丶XianGang  阅读(272)  评论(0编辑  收藏  举报