要做一个工作日志,要求只允许添加昨天、今天和以后的日志。这个日期怎么来判断?  元月一号这种特殊日期(元月一号前一天的年份小一、月份大11)怎么处理?  用jsp

解决方案 »

  1.   

    /**
     * Function Detail  : 获取当前日期
     * @param parrStr  : 被转换数组
     * @return         : 如果数组长度大于0
     */
    public static String getCurrenDate()
    {
    SimpleDateFormat pobjSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date pdatcurrentTime = new Date();
    String  pstrCruuentTime = pobjSimpleDateFormat.format(pdatcurrentTime);
    return pstrCruuentTime;
    }

    public static String getCurrenTime()
    {
            SimpleDateFormat pobjSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date pdatcurrentTime = new Date();
            String  pstrCruuentTime = pobjSimpleDateFormat.format(pdatcurrentTime);
    return pstrCruuentTime;
    }

    //获取几天以后的日期 
    //pintDay: 几天

    public static String getNextOfDate(int pintDay)
    {
    GregorianCalendar worldTour = new GregorianCalendar();
    worldTour.add(GregorianCalendar.DATE, pintDay); 
    Date d = worldTour.getTime();
    DateFormat df = DateFormat.getDateInstance();
    String s = df.format(d);
    return s;
    }

    //获取几月以后的日期 
    //pintMonth: 几月

    public static String getNextOfMonth(int pintMonth)
    {
    GregorianCalendar worldTour = new GregorianCalendar();
    worldTour.add(GregorianCalendar.MONTH, pintMonth); 
    Date d = worldTour.getTime();
    DateFormat df = DateFormat.getDateInstance();
    String s = df.format(d);
    return s;
    }
    够你用了
      

  2.   

    //判断date是否昨天凌晨之后
    public static boolean isValidDate(Calendar date) {
    Calendar now = new GregorianCalendar();
    Calendar criticalDate = new GregorianCalendar(
    now.get(Calendar.YEAR), 
    now.get(Calendar.MONTH), 
    now.get(Calendar.DAY_OF_MONTH));
    criticalDate.add(Calendar.DAY_OF_YEAR, -1);

    if (!date.before(criticalDate))
    return true;
    return false;
    }
    目前还没有发现什么问题,楼主看下,有什么不符合要求的请说出来大家一起讨论
      

  3.   

    楼上说的正确,但是能在前台处理的最好在前台处理,建议用javascript实现