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

来源:互联网 发布:矩阵乘法优化 编辑:程序博客网 时间:2024/05/23 18:45
/** 将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;    }}

0 0
原创粉丝点击