Win a copy of Svelte and Sapper in Action this week in the JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Conversion of String to Date

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic