• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parsing date/time field

 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, im trying to parse a field of type timestamp. member.end is of type timestamp. this is wut im doing:

String m = req.getParameter("end");
if (m == null || m.equals(""))
member.end = null;
else
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date end = sdf.parse(m, new ParsePosition(0));
if ( end == null || end.equals(""))
{
member.end = null;
}
else
{
member.end.setTime(end.getTime());
}
}
it sets end = null when i try to parse it above using java.util.date = sdf.parse(----)when it should be setting it into formatted value of "m"...any suggestions???..i have no idea wut else to do....
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the JavaDoc for parse( String, ParsePosition ):
Returns:
A Date, or null if the input could not be parsed
Therefore, I must guess that your input is not getting parsed for one reason or another, probably because it is not exactly matching your format. A safer way is to call parse( String ) and handle the exception.
 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey David,
Thanks for your suggestion. I tried that and it worked..thanks..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!