0

我使用日期选择器来选择日期格式。现在,将这个日期从 jsp 页面传递到 servlet 页面,而不是传递我输入的 sysdate 正在传递的日期。



    Calendar cal = Calendar.getInstance();
    String getdate = request.getParameter("selectDate");
    String [] date = getdate.split("-");

    int date1 = Integer.parseInt(date[0].trim());
    int month = Integer.parseInt(date[1].trim());
    int year = Integer.parseInt(date[2].trim());
    java.sql.Date sD=new java.sql.Date(cal.getTimeInMillis());
    System.out.println(sD);

这些是一些系统输出

In Book Support
In Database Connection
Driver is still loading...
Driver Loaded.....
Connection established.....
2013-10-28
 support_id=0, booking_date=2013-10-28, descriprtion=asdasd, address=sadas, contact_number=234]
In Add Support
 support_id=0, booking_date=2013-10-28, descriprtion=asdasd, address=sadas, contact_number=234]
1record added
4

1 回答 1

0
Calendar cal = Calendar.getInstance();
java.sql.Date sD=new java.sql.Date(cal.getTimeInMillis());
System.out.println(sD);

您创建了新的日历实例,因此结果

用于SimpleDateFormat解析接收StringDate并使用它来创建更多Date实例(如果需要)

于 2013-10-28T17:44:16.903 回答