import java.text.SimpleDateFormat;
import java.util.Date;
//将long字符串转换成格式时间输出
public class LongToString {
public static void main(String argsp[]){
String time="1256006105375";
Date date=new Date(Long.parseLong(time));
SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
time=formatter.format(date);
System.out.println(time);
}
}
将20101125102503转换成2010-11-25 10:25:03输出
import java.text.SimpleDateFormat;
import java.util.Date;
public class StringToDate {
public static void main(String argsp[]) throws Exception{
String time="20101125102503";
SimpleDateFormat formatter1=new SimpleDateFormat("yyyy-HH-dd HH:mm:ss");
SimpleDateFormat formatter2=new SimpleDateFormat("yyyyHHddHHmmss");
time=formatter1.format(formatter2.parse(time));
System.out.println(time);
}
}