reset password
Author Message
Amedrano
Posts: 80
Posted 18:31 Nov 10, 2014 |

I'm getting


java.text.ParseException: Unparseable date: "11/13/2014"
    at java.text.DateFormat.parse(DateFormat.java:337)
    at dl.servlet.CheckOutItem.doPost(CheckOutItem.java:95)

when I try to parse a String from a parameter into a date.

what am I doing wrong exactly?

xytian
Posts: 70
Posted 18:37 Nov 10, 2014 |

check this line: CheckOutItem.java:95

raywu64
Posts: 44
Posted 19:03 Nov 10, 2014 |

I think it has to be something in this form: "07/10/96 4:5 PM, PDT"

It might be easier if you just store dates as strings instead of an object.

xytian
Posts: 70
Posted 19:07 Nov 10, 2014 |
raywu64 wrote:

I think it has to be something in this form: "07/10/96 4:5 PM, PDT"

It might be easier if you just store dates as strings instead of an object.

I think you have to do some conversion in order to tell whether an item is overdue or not.

Research about SimpleDateFormat to make sure your are parsing the string correctly.

https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Last edited by xytian at 19:07 Nov 10, 2014.
Amedrano
Posts: 80
Posted 19:13 Nov 10, 2014 |
xytian wrote:
raywu64 wrote:

I think it has to be something in this form: "07/10/96 4:5 PM, PDT"

It might be easier if you just store dates as strings instead of an object.

I think you have to do some conversion in order to tell whether an item is overdue or not.

Research about SimpleDateFormat to make sure your are parsing the string correctly.

https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

I'd like for them to be "Date" objects in order to compare them.

I did the conversion using "SimpleDateFormat" called "ft"

String dueBackDate = request.getParameter( "dueBackDate" );
        Date d = new Date();
        try
        {
            d = ft.parse( dueBackDate );      <--------This Is Line 95
        }
        catch (ParseException e)
        {
            e.printStackTrace();
        }
        // setDueBackDateForItem
        item.setDueDate(d);

Last edited by Amedrano at 19:15 Nov 10, 2014.
raywu64
Posts: 44
Posted 19:22 Nov 10, 2014 |

I think the problem with that is that SimpleDateFormat requires the time as well. Try finding a simpler date object for this homework.

 

You can also split the string date and parse the string integers, then compare using a few if statements

xytian
Posts: 70
Posted 19:25 Nov 10, 2014 |
I'd like for them to be "Date" objects in order to compare them.

I did the conversion using "SimpleDateFormat" called "ft"

String dueBackDate = request.getParameter( "dueBackDate" );
        Date d = new Date();
        try
        {
            d = ft.parse( dueBackDate );      <--------This Is Line 95
        }
        catch (ParseException e)
        {
            e.printStackTrace();
        }
        // setDueBackDateForItem
        item.setDueDate(d);

What's your df?

To parse string as you described, df should look like

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

------------------------------------------------------------

I just looked at the assignment and it should be "M/d/yyyy"

Last edited by xytian at 19:33 Nov 10, 2014.
Amedrano
Posts: 80
Posted 19:32 Nov 10, 2014 |
xytian wrote:
I'd like for them to be "Date" objects in order to compare them.

I did the conversion using "SimpleDateFormat" called "ft"

String dueBackDate = request.getParameter( "dueBackDate" );
        Date d = new Date();
        try
        {
            d = ft.parse( dueBackDate );      <--------This Is Line 95
        }
        catch (ParseException e)
        {
            e.printStackTrace();
        }
        // setDueBackDateForItem
        item.setDueDate(d);

What's your df?

To parse string as you described, df should look like

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

I think you meant "ft"

SimpleDateFormat ft = new SimpleDateFormat( "M/d/yyyy " );

xytian
Posts: 70
Posted 19:37 Nov 10, 2014 |

I think you meant "ft"

SimpleDateFormat ft = new SimpleDateFormat( "M/d/yyyy " );

You have a space in "M/d/yyyy "

Amedrano
Posts: 80
Posted 19:41 Nov 10, 2014 |
xytian wrote:

You have a space in "M/d/yyyy "

oh wow...I think that was the problem.

thank you