Date d1 = (new SimpleDateFormat("dd/MM/yyyy")).parse("21/09/2001").getTime();

解决方案 »

  1.   

    String str1="2001-10-25 21:10:00";
    java.util.Date dateToday =java.util.Date.valueOf(str1); 
    java.util.Date dateTomorrow = new java.util.Date(dateToday.getTime() + 8*60*60*1000);
      

  2.   

         int timeElements[];
         int i = 0;
         StringTokenizer str2 = new StringTokenizer(str1, "-/ :", false );
         while(str2.hasMoreTokens()){
           timeElements[i] = Integer.parseInt(str2.nextToken().trim());
           i++;
         }
         //now you get the Date.
         Date aDate = new Data(timeElements[0],timeElements[1],timeElements[2],timeElements[3],timeElements[4],timeElements[5]);     long aLog = aDate.getTime() + 8*100*60*60;     //now you get the Date  8 hours later.
         Date otherDate = new Date(aLog);
      

  3.   

    : hexiaofeng(java爱好者)
    好像是
    java.sql.Date.valueOf()
      

  4.   

    To:hexiaofeng(java爱好者),
      同意judgement_sword(没什么),Java.util.Date没有valueOf()的 To:judgement_sword(没什么)
    另好像java.sql.Date.valueOf也不行,他的参数只能是yyyy-mm-dd
    不能时间的yyyy-mm-dd HH:MI:SS
    我先看看你的例子,thx!
      

  5.   

    String str1="2001-10-25 21:10:00";
    Date dt = new java.text.SimpleDateFormat("YYYY-MM-DD HH:mm:ss").parse(str1);
    Date dt2;
    Calendar cal = Calendar.getInstance();cal.setTime(dt);
    cal.add(Calendar.HOUR,+8);
    dt2 = cal.getTime();没有测试,大概应该没问题拉。
      

  6.   

    import java.util.Date;
    import java.text.*;class lal 

      
    public static void main(String[]args) 

       lal p = new lal();
       p.p();

    public void p()
    {
       String str1="2001-10-25 21:10:00";
       System.out.println(str1);
       try{
       long d1 = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(str1).getTime(); 
       System.out.println(d1);
       Date dateTomorrow = new Date(d1+ 60*8*60*1000); 
       System.out.println(dateTomorrow.toString());
       }catch(ParseException p){
       }}
      

  7.   

    你们的方法都不错。
    我现在碰到的问题是,把d1,d2注册到JDBC调用存储过程做参数时还是碰到了问题!
    CallableStatement cstmt = conn.prepareCall("{call assign_conf(?,?,?)}");
    cstmt.setDate(1,d1); 
    cstmt.setDate(2,d2);
    cstmt.registerOutParameter(4,Types.INTEGER);
    不能通过,该Oracle存储过程的前两个参数为Date型的。
    我应该如何把"2001-10-25 21:10:00"这样的时间参数传进去?
      

  8.   

    call assign_conf(to_date("2001-10-25 21:10:00","HH24MISS"))
    关键看你都需要哪些了,也可以先把这个时间字符串分解之后在使用to_date(),在他的第二个参数中指定得到什么时间
      

  9.   

    /*String=>java.util.Date  */
    ......
    cstmt.setDate(1,new java.sql.Date(d1.getTime())); 
    cstmt.setDate(2,new java.sql.Date(d2.getTime()));
      

  10.   

    To:sunjiujiu(芳芳) 
    调用存储过程可以这样传递参数的吗?
    我的存储过程接口: CREATE or REPLACE PROCEDURE assign_conf(d1 in Date,d2 in Date,id out number) .....
    用JDBC调用该存储过程时,是必须传递Date型的参数进去,不可能像你这样传递的吧
      

  11.   

    刚刚查了一下文档,发现java.sql.Date 只包含"YYYY-MM-DD",时分秒好像都被归零了!
    试了java.sql.Timestamp,解决了直接用Date传递的问题,并成功了!!
    ........
      String start_time ="2001-10-25 20:20:00";
      long dt = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(start_time).getTime();
      java.sql.Timestamp d1 = new java.sql.Timestamp(dt);
      java.sql.Timestamp d2 = new java.sql.Timestamp(dt+8*60*60*1000);CallableStatement cstmt = conn.prepareCall("{call assign_proc(?,?,?)}");
    cstmt.setTimestamp(1,d1);
    cstmt.setTimestamp(2,d2);
    cstmt.registerOutParameter(3,Types.INTEGER);
    cstmt.executeQuery();
    int id =cstmt.getInt(3);
    .........想到更好的方法,一起讨论。 
      

  12.   

    Oracle doesn't accept milliseconds part in the Date object, Timestamp seperate Milliseconds into Nanoseconds.
    Oracle JDBC driver ignores Nanoseconds part to insert the data.