Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date format in java

 
jashaswini jagadeb
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.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • 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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
Vikash Ananda
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java 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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic