java 10位和13时间戳转日期格式

/*
* 将10 or 13 位时间戳转为时间字符串
* convert the number 1407449951 1407499055617 to date/time format timestamp
*/
public static String timestamp2Date(String str_num,String format ) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    if (str_num.length() == 13) {
        String date = sdf.format(new Date(Long.parseLong(str_num)));
        LogUtil.debug("timestamp2Date"+ "将13位时间戳:" + str_num + "转化为字符串:", date);
        return date;
    } else {
        String date = sdf.format(new Date(Integer.parseInt(str_num) * 1000L));
        LogUtil.debug("timestamp2Date" + "将10位时间戳:" + str_num + "转化为字符串:", date);
        return date;
    }
}

你可能感兴趣的:(Java)