• Android之判断时间是否为今天


    字符串:      sdate =  2013-07-16 13:35:02

    /**
         * 判断给定字符串时间是否为今日
         * @param sdate
         * @return boolean
         */
        public static boolean isToday(String sdate){
            boolean b = false;
            Date time = toDate(sdate);
            Date today = new Date();
            if(time != null){
                String nowDate = dateFormater2.get().format(today);
                String timeDate = dateFormater2.get().format(time);
                if(nowDate.equals(timeDate)){
                    b = true;
                }
            }
            return b;
        }
    
    /**
         * 将字符串转位日期类型
         * @param sdate
         * @return
         */
        public static Date toDate(String sdate) {
            try {
                return dateFormater.get().parse(sdate);
            } catch (ParseException e) {
                return null;
            }
        }
    
    private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() {
            @Override
            protected SimpleDateFormat initialValue() {
                return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            }
        };
    
    private final static ThreadLocal<SimpleDateFormat> dateFormater2 = new ThreadLocal<SimpleDateFormat>() {
            @Override
            protected SimpleDateFormat initialValue() {
                return new SimpleDateFormat("yyyy-MM-dd");
            }
        };
  • 相关阅读:
    HDU6301 SET集合的应用 贪心
    线段树与树状数组的对比应用
    树状数组
    JDBC链接MySQL数据库
    HDU4686Arc of Dream 矩阵快速幂
    HDU1757矩阵快速幂
    B1013. 数素数 (20)
    B1023. 组个最小数 (20)
    [教材]B1020. 月饼 (25)
    [教材]A1025. PAT Ranking (25)
  • 原文地址:https://www.cnblogs.com/lee0oo0/p/3194604.html
Copyright © 2020-2023  润新知