• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parsing date/time field

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey David,
Thanks for your suggestion. I tried that and it worked..thanks..
 
reply
    Bookmark Topic Watch Topic
  • New Topic