Java is 10-bit and 13-bit timestamp, convert format viewable time

df

sdfd

 

dfasd

 

 

dsfds

 

Accounting Floor

If the specified interface document type String, note must not contain l, can only contain numbers

public static String timestamp2Date(String str_num) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (str_num.length() == 13) {
            String date = sdf.format(new Date(toLong(str_num)));
            System.out.println ( "the timestamp 13:" + str_num + "into a string:" + date);
            return date;
        } else {
            String date = sdf.format(new Date(toLong(str_num) * 1000));
            System.out.println ( "10-bit timestamp:" + str_num + "into a string:" + date);
            return date;
        }
    }

    public static long toLong(String obj) {
         return Long.parseLong(obj);
    }

    @Test
    public void Te(){
        String aaa = "1566802997242";
        String bbb = "1566801239";
        System.out.println(aaa.length());
        System.out.println(bbb.length());
        timestamp2Date(aaa);
        timestamp2Date(bbb);



    }

Guess you like

Origin www.cnblogs.com/qianjinyan/p/11413326.html