Date and time selection in java

I am very new to java and I want the user to enter the time and date for which the football match should be scheduled. I am using SWING jForm as an interface. Having received this date, I also want to add it to the database. After a lot of searching, I could not find the correct code, or I cannot figure it out. I am working on a rather long project and am not leaving to see the tutorial. Any help in this regard would be greatly appreciated.

Or just tell me if I have "YYYY / MM / DD HH: MM: ss: SSS" in String, then how can I convert this to a date format?

Date d = (Date)dateString didn't worked. 

Note. I use drag and drop to create elements in jFrame.

+1
source share
3 answers

You can try the following:

 SimpleDateFormat str =new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy"); 

like this:

 public static void main(String[] args) throws Exception { String str = "Sat Nov 23 20:29:30 JST 2013"; DateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy", Locale.ENGLISH); Date d = df.parse(str); System.out.println(d); } 

Also check out SimpleDateFormat

+1
source

(a) Doing last-minute dates is a bad idea. Date-time can be a surprisingly thorny topic.

(b) See my answer to a similar question.

My code sample uses a third-party Joda-Time library, a popular replacement for the obviously bad java.util.Date/ Calendar classes bundled with Java.

This code is exactly what you need, although you need:

  • Adjust the format for your specific needs.
  • Adjust the time zones according to what you are processing.

Do most of your date work with Joda-Time. At the beginning and at the end, convert Joda-Time DateTime objects and java.util.Date objects. Lots of Q&A here in StackOverflow to show you this conversion.

+1
source

Use Date.parse(String) , see javadoc for more details.

0
source

All Articles