Here you can find the source of isInYear(String dateStr, int year)
public static boolean isInYear(String dateStr, int year)
//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; } }