Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2006

Tip: Looking for answers? Try searching our database.

Displaying System Time In Java

Thread view: 
christopher_board@yahoo.co.uk - 31 Aug 2006 22:06 GMT
I would like a label in my java application to display the system time
and date. But i don't know how to do this. Is it as simple as saying
setText. i.e. lblTime.setText("" + ). I would like to know what goes
after the plus.

Thank you very much for your help.
Paul Hamaker - 31 Aug 2006 22:10 GMT
For something crude, you could do :
lblTime.setText("" +  new Date() );
but for nice formatting, have a look at this :
http://javalessons.com/cgi-bin/fun/java-tutorials-main.cgi?sub=gui&ses=ao789
Lesson g47. Date and time
IchBin - 01 Sep 2006 02:24 GMT
> For something crude, you could do :
> lblTime.setText("" +  new Date() );
> but for nice formatting, have a look at this :
> http://javalessons.com/cgi-bin/fun/java-tutorials-main.cgi?sub=gui&ses=ao789
> Lesson g47. Date and time

You want to use the Class SimpleDateFormat.

SimpleDateFormat myFormat =
    new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");

lblTime.setText(myFormat.format(new Date()));

You just need to look at the Date Time format you want to actually use.
You only have to create one SimpleDateFormat field and then just reuse
that as the second line of code does above. You can find that on the
Class SimpleDateFormat API page at:

http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html

Signature

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA              http://weconsultants.phpnet.us
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)

christopher_board@yahoo.co.uk - 01 Sep 2006 22:06 GMT
Thanks very much for your help I have done it and it works fine. Thanks
very much once again.

> For something crude, you could do :
> lblTime.setText("" +  new Date() );
> but for nice formatting, have a look at this :
> http://javalessons.com/cgi-bin/fun/java-tutorials-main.cgi?sub=gui&ses=ao789
> Lesson g47. Date and time


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.