aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Converting Textfield to Date field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Converting Textfield to Date field" Watch "Converting Textfield to Date field" New topic
Author

Converting Textfield to Date field

RaviSingh Kumar
Ranch Hand

Joined: Sep 04, 2007
Posts: 52
i am converting JTextField value to Date datatype using SimpleDateFormatter("dd/mm/yyyy"). The output is given as:

Sun Jan 22 00:10:00 GMT+05:30 2006

But while inserting data into database, i want that the date should be in this form '22-Jan-2006'.

Can anyone give me suggestion to this.

Thanks in advance
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by RaviSingh Kumar:
i am converting JTextField value to Date datatype using SimpleDateFormatter("dd/mm/yyyy"). The output is given as:

Sun Jan 22 00:10:00 GMT+05:30 2006

But while inserting data into database, i want that the date should be in this form '22-Jan-2006'.

Can anyone give me suggestion to this.


For input, it's probably easiest to use JFormattedTextField:

Presuming you're using JDBC to access the database, it's probably easiest to use a PreparedStatement and let the JDBC driver worry about conversion:

[edit: "dd/mm/yyyy" -> "dd/MM/yyyy" ('mm' is minute-in-hour, not month-in-year)]
[ February 12, 2008: Message edited by: Brian Cole ]

bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting Textfield to Date field