Java Year From isInYear(String dateStr, int year)

Here you can find the source of isInYear(String dateStr, int year)

Description

is In Year

License

Open Source License

Declaration

public static boolean isInYear(String dateStr, int year) 

Method Source Code

//package com.java2s;
/**/*from   www .  ja  va2  s  . c  om*/
 * DateUtil.java ,By AOSA_TECH AOSAProject at 2011-8-11 ????06:53:44
 * Copyright (c) 2011, AOSA_TECH, Ltd. All right reserved.
 * AOSA_TECH PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * @Project AOSAProject
 * @version V1.0.0
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

    public static boolean isInYear(String dateStr, int year) {
        boolean flag = false;
        String[][] yearedge = getYearDateStr(year);
        SimpleDateFormat frm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = frm.parse(dateStr);
            String startTime = yearedge[0][0];
            String endTime = yearedge[0][1];
            Date startDate = frm.parse(startTime);
            Date endDate = frm.parse(endTime);
            if (startDate.getTime() <= date.getTime() && date.getTime() <= endDate.getTime()) {
                flag = true;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return flag;
    }

    public static String[][] getYearDateStr(int year) {
        String[][] dateStr = { { year + "-01-01 00:00:00", year + "-12-31 23:59:59" }, };
        return dateStr;
    }
}

Related

  1. getYears(Integer limit)
  2. getyears(List numberList)
  3. getYearStart(int year)
  4. getYearStart(long ts)
  5. getYearStartTime()
  6. setYears(Date date, int amount)
  7. toNowYear(Date date)
  8. toShortW3CDTF(Date d, boolean yearOnly)
  9. year()