| | |
| | | import java.util.Date; |
| | | |
| | | public class ThreadLocalUtil { |
| | | |
| | | public static String TIME_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; |
| | | public static String TIME_YYYY_MM_DD = "yyyy-MM-dd"; |
| | | public static String TIME_YYYY_MM_DD_HH_MM_SS_UNION = "yyyyMMddHHmmss"; |
| | | public static String TIME_YYYY_MM_DD_HH_MM_SS_UNION2 = "yyyy-MM-dd_HH_mm_ss"; |
| | | |
| | | public static ThreadLocal<SimpleDateFormat> sdf = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); |
| | | public static ThreadLocal<SimpleDateFormat> sdfwithOutday = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy_MM")); |
| | | public static ThreadLocal<SimpleDateFormat> sdfwithday = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd")); |
| | |
| | | } |
| | | return timeStr; |
| | | } |
| | | |
| | | public static String format(String timeFormat,Date date) { |
| | | ThreadLocal<SimpleDateFormat> formatThreadLocal = ThreadLocal.withInitial(() -> new SimpleDateFormat(timeFormat)); |
| | | SimpleDateFormat format = formatThreadLocal.get(); |
| | | return format.format(date); |
| | | } |
| | | } |