Results 1 to 2 of 2
Thread: datetime on a jtextfield
- 03-02-2010, 12:11 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 6
- Rep Power
- 0
- 03-02-2010, 01:08 PM #2
The JTextField works with a String right, setText().
where a database datetime is going to be a java.util.Date (or a java.sql.Date, or a java.sql.Timestamp)
The java.text.SimpleDateFormat is handy for converting between strings and dates. You specify the formatting string, see the javadoc
Where in this example I assume we have read a timestamp object,
Java Code:SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yyyy"); Timestamp myDatabaseTime = // fetched from database right... java.util.Date aDate = new java.util.Date(myDatabaseTime.getTime()); // not even required to convert it, timestamp extends Date. jTextField.setText(fmt.format(aDate));
Similar Threads
-
JTextField
By gancio in forum AWT / SwingReplies: 20Last Post: 08-26-2009, 03:11 PM -
How to highlight a particular day in DateTime / Calendar widget?
By Mitja in forum SWT / JFaceReplies: 2Last Post: 08-05-2009, 11:00 AM -
how to access jTextField of one JFrame1 from JFrame2 & Modify JTextField contents
By sumit1mca in forum AWT / SwingReplies: 1Last Post: 01-30-2009, 06:44 PM -
JtextField
By kashifu in forum Advanced JavaReplies: 2Last Post: 06-27-2008, 04:25 PM -
help with JTextfield
By gary in forum New To JavaReplies: 4Last Post: 07-11-2007, 01:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks