• DateUtil(SimpleDateFormat)


    import java.util.Calendar;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    
    public class DateUtil
    {
        private static SimpleDateFormat format1;
        private static SimpleDateFormat format2;
        private static SimpleDateFormat format3;
        private static SimpleDateFormat format4;
        
        static {
            DateUtil.format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            DateUtil.format2 = new SimpleDateFormat("yyyy-MM-dd");
            DateUtil.format3 = new SimpleDateFormat("yyyyMMddHHmmss");
            DateUtil.format4 = new SimpleDateFormat("HH:mm:ss");
        }
        
        public static Date getNow() {
            return Calendar.getInstance().getTime();
        }
        
        public static String format_yyyy_MM_dd_HH_mm_ss(final Date date) {
            return DateUtil.format1.format(date);
        }
        
        public static String format_yyyy_MM_dd(final Date date) {
            return DateUtil.format2.format(date);
        }
        
        public static String format_yyyyMMddHHmmss(final Date date) {
            return DateUtil.format3.format(date);
        }
        
        public static String format_HH_mm_ss(final Date date) {
            return DateUtil.format4.format(date);
        }
        
        public static String format(final String pattern, final Date date) {
            return new SimpleDateFormat(pattern).format(date);
        }
        
        public static Date getTimeForAnyHourInToday(final int hour) {
            final Calendar c = Calendar.getInstance();
            c.set(10, hour);
            c.set(12, 0);
            c.set(13, 0);
            c.set(14, 0);
            return c.getTime();
        }
    }
    这个博客主要是javaEE相关或者不相关的记录, hadoop与spark的相关文章我写在下面地址的博客啦~ http://www.cnblogs.com/sorco
  • 相关阅读:
    Python3全栈学习目录
    五句话搞定javavscript作用域
    Python线程池
    luogu4016 负载平衡问题
    luogu2756 飞行员配对方案问题
    luogu1251 餐巾计划问题
    luogu3386 【模板】二分图匹配 匈牙利算法 hdu2063 过山车 dinic
    luogu3381 【模板】最小费用最大流
    luogu3376 【模板】网络最大流 dinic
    luogu2740 [USACO4.2]草地排水Drainage Ditches 最大流EK
  • 原文地址:https://www.cnblogs.com/orco/p/6235938.html
Copyright © 2020-2023  润新知