This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How do I get a current date and time in a JLabel? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I get a current date and time in a JLabel?" Watch "How do I get a current date and time in a JLabel?" New topic
Author

How do I get a current date and time in a JLabel?

Aaron Parker
Greenhorn

Joined: Jan 31, 2004
Posts: 27
I can't get this to compile. How do I get a date into the label?
Aaron Parker
Greenhorn

Joined: Jan 31, 2004
Posts: 27
(Before I had Date dateAndTime = new Date(); just above JLabel dateTime)
Carlos Failde
Ranch Hand

Joined: Oct 20, 2000
Posts: 84
Howdy.
Date dateAndTime = Calendar.getInstance().getTime();
JLabel dateTime = new JLabel(dateAndTime.toString());
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How do I get a current date and time in a JLabel?