如: 筛选一段时间(9月份到明年3月份)内过生日会员的方法 //日期的格式是MM-DDString beginDate="09-01";
String endDate="03-01"; //当前日期
String currentDate="2013-01-10";
判断currentDate是否在beginDate和endDate之间,JAVA实现
javaDate

解决方案 »

  1.   

    SimpleDateFormat dateformat = new SimpleDateFormat("mm-dd");
    Date current=dateformat.parse(currentDate);
    Date begin=dateformat.parse(beginDate);
    Date end=dateformat.parse(endDate);
    if(current.getTime()>=begin.getTime() && current.getTime()<=end.getTime())
        return true;
      

  2.   

    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    /**
     *
     * @date   11/01/2013
     */
    public class DateCondition {
      
      public static void main(String[] args) {
        
        System.out.println(new DateCondition().match("2013-01-10"));
        System.out.println(new DateCondition().match("2013-09-01"));
        
        System.out.println(new DateCondition().match("2013-03-01"));
        System.out.println(new DateCondition().match("2013-05-10"));
      }
      
      private static final DateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd");
      
      private String beginDate = "03-01";
      private String endDate = "09-01";
      
      public boolean match(String date) {
        
        try {
          
          Date d = FORMAT.parse(date);
          Date from = FORMAT.parse(date.substring(0, 5) + beginDate);
          Date to = FORMAT.parse(date.substring(0, 5) + endDate);
          return (d.equals(from) || d.after(from)) && d.before(to);
        }
        catch(ParseException ex) {
          
          throw new IllegalArgumentException(ex);
        }
      }
    }
      

  3.   


      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
      SimpleDateFormat formatmd = new SimpleDateFormat("MM-dd");
      String beginDate="09-01";
      String endDate="03-01";
      String currentDate="2013-01-10";
      Date now = null;
      try{
         now =format.parse(currentDate);
     
       }catch(ParseException e){}
       String current = formatmd.format(now);
       if(current.compareTo(beginDate)>=0 && current.compareTo(endDate)<=0){
        System.out.println("yes");
        }借助于日期格式与字符串之间的转换