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

date format in java

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi...
i want to get the date from textField of any format in swing. (i.e.dd/mm/yyyy or dd.mm.yyyy or dd-mm-yyyy) .please reffer the code.
please help me.
thanks in advance.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

jashaswini jagadeb wrote:hi...
i want to get the date from textField of any format in swing. (i.e.dd/mm/yyyy or dd.mm.yyyy or dd-mm-yyyy) .please reffer the code.
please help me.
thanks in advance.



Hi jashaswini, this is NotACodeMill, so we won't just give you code to use, but we can help you with your problem. Have a look at the DateFormat, and its implementing SimpleDateFormat child classes. They provide tools for parsing many of the common date formats - with the ability to pass in your own custom format String. You won't be able to use a single format to parse 'any format', you will have to provide a specific set of formats that are recognized.

Take a look at those classes and try out some code. If you have problems come on back and let us know and we can help you work through them.
 
Marshal
Posts: 70266
282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jashaswini jagadeb,

There are many samples that you can google that gives you a button on pressing them you can see the calender where specific dates can be clicked which you can trap. You can use these dates for your application. Please find something similar. This will eliminate users to make mistakes.

Thanks,
Vikash Anand.
 
Sheriff
Posts: 21999
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to try parsing using a DateFormat without any exceptions thrown, use the parse method that takes a ParsePosition:
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic