http://expert.csdn.net/Expert/topic/1058/1058703.xml?temp=.5492823

解决方案 »

  1.   

    使用SimpleDateFormat,
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(dateString);
    得到date后使用Calendar的add或者roll方法,增加一天,就可以得到你所需要的结果了
      

  2.   

    <%@ page language="java"%>
    <%@ page import="java.util.*" %>
    <%@ include file="../../Function/connection.jsp" %>
    <%@ include file="../../Function/function.jsp" %>
    <%@ page contentType="text/html;charset=big5"%>
    <%
    //我不能很好地領悟您的意思.
    //不過下段代碼僅供參考:
    String _inputDate=null; //所選日期
    String _nextDate=null; //所選日期的次日
    _inputDate=request.getParameter("Date");
    java.text.SimpleDateFormat _sdf=new java.text.SimpleDateFormat("yyyy/MM/dd");
    if(_inputDate==null)
    {
    Calendar _today = new GregorianCalendar();
    _today.add(Calendar.DATE,-1);
    java.util.Date _yesteday=_today.getTime();
    _inputDate=_sdf.format(_yesteday).toString();

    }
    int _intYear=(new Integer(_inputDate.substring(0,4))).intValue();
    int _intMonth=(new Integer(_inputDate.substring(5,7))).intValue();
    int _intDay=(new Integer(_inputDate.substring(8,10))).intValue();
    Calendar _tempCalendar=new GregorianCalendar(_intYear,_intMonth-1,_intDay);
    _tempCalendar.add(Calendar.DATE,1);
    java.util.Date _tempDate=_tempCalendar.getTime();
    _nextDate=_sdf.format(_tempDate).toString();<input type="text" name="Date">
      

  3.   

    <%@ page language="java"%>
    <%@ page import="java.util.*" %>
    <%@ include file="../../Function/connection.jsp" %>
    <%@ include file="../../Function/function.jsp" %>
    <%@ page contentType="text/html;charset=big5"%>
    <%
    //我不能很好地領悟您的意思.
    //不過下段代碼僅供參考:
    String _inputDate=null; //所選日期
    String _nextDate=null; //所選日期的次日
    _inputDate=request.getParameter("Date");
    java.text.SimpleDateFormat _sdf=new java.text.SimpleDateFormat("yyyy/MM/dd");
    if(_inputDate==null)
    {
    Calendar _today = new GregorianCalendar();
    _today.add(Calendar.DATE,-1);
    java.util.Date _yesteday=_today.getTime();
    _inputDate=_sdf.format(_yesteday).toString();

    }
    int _intYear=(new Integer(_inputDate.substring(0,4))).intValue();
    int _intMonth=(new Integer(_inputDate.substring(5,7))).intValue();
    int _intDay=(new Integer(_inputDate.substring(8,10))).intValue();
    Calendar _tempCalendar=new GregorianCalendar(_intYear,_intMonth-1,_intDay);
    _tempCalendar.add(Calendar.DATE,1);
    java.util.Date _tempDate=_tempCalendar.getTime();
    _nextDate=_sdf.format(_tempDate).toString();
    %>
    <input type="text" name="Date">
      

  4.   

    private GregorianCalendar transStrToDate(String strDate)throws ParseException{
    DateFormat df = DateFormat.getDateInstance();
    Date date=null;
    try{
    date=df.parse(strDate);
    }catch(ParseException e){
    throw e;
    }
    GregorianCalendar temp=new GregorianCalendar();
    temp.setTime(date);
    return temp;
    }得到这个日期
    GregorianCalendar fromDate;
    try{
    fromDate=transStrToDate(strFromDate); }catch(ParseException e){
    }
    然后增加
    fromDate.add(Calendar.DAY_OF_MONTH,1);
      

  5.   

    不好意思,都怪我没说明白!谢谢楼上的朋友。
    我的意思是有两个文本域:“开始日期”:startdate;“申请天数”:date 当用户在startdate中填写如yyyy-mm-dd格式的日期,在date中填入个数字,然后系统可以自动算出“结束日期”,就是"开始日期"加上"申请天数".上面的文章我看了,还是不太懂。request.getParameter("startdate")得到的应该是一个字符串吧,如何计算呢?
    谢谢大家了
      

  6.   

    在数据库中处理比较方便,mydate+1就是mydate的后一天
      

  7.   

    加入<%@ page import="java.util.Date" %>String str = "";
    Date date = new Date();
        
    str = startdate.substring(0,4);        //年 
    date.setYear(Integer.parseInt(str));
        
    str = startdate.substring(5,7);        //月  Date 的月是 0~~~11
    date.setMonth(Integer.parseInt(str)-1);  
        
    str = startdate.substring(8,10);       //日
    date.setDate(Integer.parseInt(str));  int intDate = date.getDate();
    intDate += 1;                           //加上申请天数,以一天为例  
    date.setDate(intDate); //获得加上申请天数天后的年月日
    int next_day = date.getDate();             
    int next_month = date.getMonth()+1;
    int next_year = date.getYear();
        
     ///合并年月日      
        if(next_day<10&&next_month<10)   //月日小于10
           next_time = next_time.valueOf(next_year)+ "-0" + next_time.valueOf(next_month)+ "-0" + next_time.valueOf(next_day);
        else
        { 
        if(next_day<10)                  //日小于10
           next_time = next_time.valueOf(next_year)+ "-" + next_time.valueOf(next_month)+ "-0" + next_time.valueOf(next_day);
        else
        {
          if(next_month<10)              //月小于10
             next_time = next_time.valueOf(next_year)+ "-0" + next_time.valueOf(next_month)+ "-" + next_time.valueOf(next_day);
          else                           //月日大于10
             next_time = next_time.valueOf(next_year)+ "-" + next_time.valueOf(next_month)+ "-" + next_time.valueOf(next_day);
          
        }
        }//next_time 就是你要的结束日期!!!!!!!!!!!