zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    java RSA加密解密
    spring boot 错误处理机制
    Redis 服务常见的几个错误解决方案
    Nginx目录遍历功能时间相差8小时
    翻过大山越过海洋看到了什么
    【分享】分层明确高度定制化的 Python Flask MVC
    编程浪子客服系统开源啦
    快速搭建一个直播Demo
    免费为网站加上HTTPS
    Mac 下安装Fiddler抓包工具
  • 原文地址:https://www.cnblogs.com/orco/p/6235938.html
Copyright © 2011-2022 走看看