Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Conversion of String to Date

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
This is shyam Kumar, in a project i need to take the date from the user and convert it to Date format. Can some one Help me in converting a date in String format to java.util.Date format .
thank you

regards
shyam
[ December 09, 2004: Message edited by: kumar shyam ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the API JavaDocs, specifically java.util.DateFormat and java.util.SimpleDateFormat. You should be able to work it out from there.
 
Sham Grandhe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul Sturrock,
thank you for advice, but ive done all that finally come to the fourm. there is a way that we can convert the Date in String format to Date but the String must be in specific format only ie for ex Aug 16, 1981. .
What I want is that, I must be able to give date in a any of the String format and able to build a Date object. ( MM/dd/yyyy, yyyy/mm/dd or dd/mm/yyyy or mm/dd/yy).
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Parsing a String to a Date where the date can be in any valid Date format is a big task. The API comes with SimpleDateFormat which is (as you can probably gather from the name) a simple extension of the abstract class DateFormat. One SimpleDateFormat object has only one date format, if you follow. What you need is to write your own extension of DateFormat so it can accept an array of formats. Any this is where it gets difficult - how do you actually workout what is a date? You need to define an complete list of formats your program can accept and have your DateFormat class's parse method handle them all.
 
Sham Grandhe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
Thank you for your suggestion, any how iam doing the same thing using three combo boxes. and validating them in the same manner.
bye bye
have a nice day

shyam
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic