*
The moose likes Swing / AWT / SWT and the fly likes Date Format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Date Format" Watch "Date Format" New topic
Author

Date Format

Milind Deodhar
Ranch Hand

Joined: Dec 06, 2000
Posts: 32
I have a frame which has a textbox , the values of which should be date and should update a date in a MS Access Database.
The date in the Access database is of Date/Time type with Short Date format.
How should I convert the string to date format which can be inserted in the database.

Meghna ks
Ranch Hand

Joined: Mar 15, 2001
Posts: 122
If you're working with swings, try using JMaskedTextField instead of a JTextField. This should make things easier for you. I guess this code should convert your String to date format.
com.symantec.itools.javax.swing.JMaskedTextField mask =
new com.symantec.itools.javax.swing.JMaskedTextField();
String maskchar = new String("0000/00/00\\ 00:00:00:00");
mask.setDatatype(com.symantec.itools.javax.swing.JMaskedTextField.datetype);
mask.setText(Your String);
mask.setMask(maskchar);
Good Luck
Meghna
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

That solution would only work if Milind was using Symantec/WebGain's Visual Cafe.

Or, if Milind was willing to use unlicensed class files.
hil
Greenhorn

Joined: Oct 30, 2001
Posts: 1
Another question regarding JMaskedTextField:
Does anyone know how to remove the underlined characters that are displayed in a JMaskedTextField? For instance, if I declare a JMaskedTextField with mask 000, i.e. three digit places, then at run-time when I focus on the JTextField "___" will appear. It's quite unsightly, seems like an odd default.
Thanks,
Hilda
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi Milind,
there are some classes that help you check the input. see the section "How to use TextFields" in the swing tutorial (java.sun.com/docs etc).
the classes java.sql.Date/Time/Timestamp have each the static method valueOf(String). you can use this as a suppletive validation and conversion.
chantal
thanujj_ns
Greenhorn

Joined: Dec 11, 2001
Posts: 1
Originally posted by Milind Deodhar:
I have a frame which has a textbox , the values of which should be date and should update a date in a MS Access Database.
The date in the Access database is of Date/Time type with Short Date format.
How should I convert the string to date format which can be inserted in the database.

u have something called Dateformat in calendar class .In that Parse method converts string to date. if u want to do vice versa, toString(calendar obj) is fine.
Thanujja
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date Format
 
Similar Threads
Date format
Insert a row into MS Access2003 successfully,But the long date(YYYY/MM/DD HH:mm:ss) was changed
Date Format
jdbc
Date format