Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



Get Date by JTextField

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 12-02-2010
Member
 
Join Date: Dec 2009
Posts: 204
Get Date by JTextField

Hello,
I would like via a form JTextField ask the user a date and format for format MM-dd-yyyy HH: mm.
If you are suggesting me the SimpleDateFormat then I can not use it, I would like the user to enter
Quote:
"12-12-2009" or "12-12-2009 11:32"
Now I need to convert the second adding "00:00" behind AC but not enough.
I need to verify that the date is. Can any one help me with this. Thanks in advance.
Reply With Quote
  #2  
Old 12-02-2010
Member
 
Join Date: Dec 2009
Posts: 192
Re: Get Date by JTextField

Hello,
I have tried this before but was unsuccessful, if you need the code what I tried then it is here
Code:
static Public String ToDate(String dt) 
    {
        DateFormat dtfrm = new SimpleDateFormat("MM-dd-yyyy HH: mm");
        try {
            dt = dtfrm.format(dt);
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        return dt;
    }
See if you can get something out of it.
Reply With Quote
  #3  
Old 12-02-2010
Member
 
Join Date: Nov 2009
Posts: 359
Re: Get Date by JTextField

Hello,
This is normal, it should pass a "dt"
Code:
dtfrm.format(...)
best is to get a date with another SimpleDateFormat
Code:
SimpleDateFormat dtfrm1 = new SimpleDateFormat ("MM-dd-yyyy");
You go once with this one for a date, you can format the date with the dtfrm you did, and it should be good.
Reply With Quote
  #4  
Old 12-02-2010
Member
 
Join Date: Nov 2009
Posts: 520
Re: Get Date by JTextField

Hello,
You take your string you pass to the method parse your SimpleDateFormat. This method throws a ParseException if the string does not match the expected format and if the string is not a valid date. The parse method returns an object you date that you can use in a format thereafter. If you need any help regarding this topic then you can post back and we will try to solve it.
Reply With Quote
  #5  
Old 12-02-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: Get Date by JTextField

Hello,
You can make a JFormattedTextField to date:
Code:
DateFormat dtfrm = new SimpleDateFormat("MM-dd-yyyy");
 chdt = new JFormattedTextField(dtfrm);
You can utilize isListen () to see if the date is valid or not otherwise in default 30-02-2007 entering it you will return 01-02-2009 or 02-04-2009 and by lenient to false it throws an exception you. I think you should already recovers your formatted string "12-12-2009" and turn it into date object and then add the hours and finally transform it into a String with the format "12-12-2009 00:00".
Reply With Quote
  #6  
Old 12-02-2010
Member
 
Join Date: Dec 2009
Posts: 204
Re: Get Date by JTextField

Hello,
For the first point, to pass a date format (). OK but why autocompletion offers me a format that parameter for a string? if the class was not overloaded with a String parameter I will not be able to compile.
For the second point
Code:
SimpleDateFormat dtfrm1 = new SimpleDateFormat ( "MM-dd-yyyy");
I tried with this pattern and just passing the string 12-12-2009. I get an error. Any ideas on this.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Get Date by JTextField"
Thread Thread Starter Forum Replies Last Post
Custom Background Icon for JTextField? melston Software Development 3 22-08-2010 01:02 PM
Display JtextField in Jpanel New ID Software Development 5 04-03-2010 12:01 PM
How to write a wrapper around the JTextField class? MAHAH Software Development 4 12-02-2010 07:01 PM
[JAVA] query results in a combobox and jtextfield Aamin Software Development 5 31-03-2009 03:20 PM
How Can i achieve the functionality of TextListener for JTextField Gap meer Software Development 4 25-10-2008 07:08 PM


All times are GMT +5.5. The time now is 05:22 AM.