Java SQL Date Check isChunjie(String date)

Here you can find the source of isChunjie(String date)

Description

is Chunjie

License

Apache License

Declaration

public static boolean isChunjie(String date) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.*;

public class Main {
    static public SimpleDateFormat MMddYYYY_HHmmss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    static public SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");

    public static boolean isChunjie(String date) {
        if (initChunJie().containsKey(date)) {
            return true;
        }/*from  www .  j  ava2  s . c om*/
        return false;
    }

    public static Map<String, String> initChunJie() {
        String[] ChunJie = { "2006-01-29", "2007-02-18", "2008-02-07", "2009-01-26", "2010-02-14", "2011-02-03",
                "2012-01-23", "2013-02-10", "2014-01-31", "2015-02-20" };

        Map<String, String> dateMap = new HashMap<String, String>();

        for (int i = 0; i < ChunJie.length; i++) {
            String curDate = ChunJie[i];
            int j = 1;
            while (j <= 7) {
                dateMap.put(curDate, curDate);
                curDate = getNextDayStr(curDate);
                j++;
            }
        }
        return dateMap;
    }

    public static String getNextDayStr(String curday) {
        java.util.Date date = str2date(curday);
        return date2str(new Date(date.getTime() + 24 * 3600 * 1000));
    }

    public static Date str2date(String str) {
        Date result = null;
        try {
            Date udate = yyyyMMdd.parse(str);
            result = new Date(udate.getTime());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String date2str(java.util.Date date) {
        if (date == null)
            return "";
        try {
            return MMddYYYY_HHmmss.format(date);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    static public String date2str(java.sql.Date date) {
        if (date == null)
            return "";
        try {
            return yyyyMMdd.format(date);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }

    }

    public static String getTime(String parrten) {
        String timestr;
        if (parrten == null || parrten.equals("")) {
            parrten = "yyyyMMddHHmmss";
        }
        java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);
        java.util.Date cday = new java.util.Date();
        timestr = sdf.format(cday);
        return timestr;
    }
}

Related

  1. isDataTypeDate(int dataType)
  2. isDate(final PropertyDescriptor pd)
  3. isDate(int colType)
  4. isDate(int dataType)