• 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

Help in using DateFormat

 
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a method that will take in a string and convert it into a Date using DateFormat.

The problem is that I am not sure what the format the string should take.

I used the date : "15-Jul-1999" which through up a java.text.ParseException: Unparseable date: "15-Jul-1999"
All I need is the day month and year not the time.

Thanks for any help

Tony

public void setMaturityDate(String date)
{
DateFormat df = DateFormat.getDateInstance();
try
{
this.maturityDate = df.parse(date);
}
catch(ParseException e)
{
System.out.println("Error "+e);
}
}
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can read the API docs and see for yourself, but it won't parse that text at all. Read the docs and see what it expects.
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Nathaniel, where can I get these docs online.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tony,

You can try this


In the above code you can see after the parsing it gives with the time then you can format the date to whatever format you want.

You can also have a look at these links

http://java.sun.com/developer/JDCTechTips/2003/tt0624.html#2
http://java.sun.com/docs/books/tutorial/i18n/format/dateFormat.html

Hope this helps



 
I brought this back from the farm where they grow the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic