package org.ljh.test.javaee; import java.text.SimpleDateFormat; import java.util.Date; public class StringToLongToDate { public static String parseTime(String s){ //将字符串转化为Long类型 Long timeLong = Long.parseLong(s); //将Long类型转化为Date Date date = new Date(timeLong); //将Date类型格式化 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = sdf.format(date); return dateString; } public static void main(String[] args){ System.out.println(parseTime("5223456789236")); } }
输出结果:2135-07-12 00:13:09