package test;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test {
public static void main(String[] args) {
format(new Date(1434093047*1000L), "yyyy-MM-dd HH:mm:ss");
System.out.println(format(new Date(1434093047*1000L), "yyyy-MM-dd HH:mm:ss"));
}
public static String format(Date date, String format) {
String ret = "";
if(date != null){
ret= getDateFormat(format).format(date);
}
return ret;
}
private static ThreadLocal<DateFormat> threadLocal = new ThreadLocal<DateFormat>();
public static DateFormat getDateFormat(String date_format)
{
threadLocal.remove();
DateFormat df = threadLocal.get();
if(df==null){
df = new SimpleDateFormat(date_format);
threadLocal.set(df);
}
return df;
}
}
秒、毫秒转日期
最新推荐文章于 2021-06-29 18:05:23 发布
本文介绍了一种使用Java进行日期格式化的有效方法,通过ThreadLocal和SimpleDateFormat的结合使用,提高了日期格式化操作的效率。文章详细展示了如何自定义日期格式,并通过实例演示了具体的应用。
1629

被折叠的 条评论
为什么被折叠?



