473,513 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System Time on Jframe

5 New Member
how can i get system date and time on my Jframe.
Jan 25 '12 #1
3 8656
rotaryfreak
74 New Member
you can use the Gregorian Calendar class to create an instance of that class and then extract the data that you need from that object

http://docs.oracle.com/javase/6/docs...nCalendar.html

once that is done, you should probably create a JLabel and set the text as the date and time that you want. You will then add it to a JPanel inside your JFrame.

Something like this:



Expand|Select|Wrap|Line Numbers
  1.  
  2. class JFrameDate{
  3. public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
  4.  
  5. //this method gets the date and time now. you can modify the
  6. //date format to not show the time
  7.  
  8. public static String timeNow() {
  9.      Calendar cal = Calendar.getInstance();
  10.      SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
  11.      return sdf.format(cal.getTime());
  12. }
  13.  
  14. public static void main(String [] args){
  15.      JFrame myFrame = new JFrame("Show Date");
  16.      myFrame.setVisible(true);
  17.  
  18.      JPanel myPanel = new JPanel();
  19.  
  20.      JLabel dateTime = new JLabel();
  21.      dateTime.setText(JFrameDate.timeNow());
  22.  
  23.      myPanel.add(dateTime);
  24.  
  25.      myFrame.add(myPanel);
  26.  }
  27. }
  28.  
i have not tested this code, but the idea is straight forward. You will have to adjust your JFrame and JPanels to the layout, size and display location you want, but i think this is a good starting point
Jan 27 '12 #2
samsmile62000
5 New Member
hey i got an error .... cannot find symbol SimpleDateFormat class
Jan 27 '12 #3
samsmile62000
5 New Member
het thanks got a solution.... it worked..thanks
Jan 27 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
4636
by: Valiz | last post by:
Hi, I am updating system time with IRIG time source which sends irregular pulses as shown below 11000011111100111111111111111111....(1-IRIG present and 0-IRIG not present) I need to update...
2
405
by: arcvonz | last post by:
We have a time critical smart client application running on Windows 2000/XP systems. Is there any reliable service that would help in syncing the local system time to atomic clock or local time at...
1
9827
by: thomasamillergoogle | last post by:
Hello, My sql server 2000 database is on a shared server that I have absolutely no control over. When i run query select getdate() it is reporting the wrong time! I am pretty sure that the...
4
16363
by: Mike Kearl | last post by:
I want to set the local Date Time of the xp systems in my organization using C# and a winform application. From what I have read this is not an easy task anymore. You have to obtain privlege...
2
5340
by: Kueishiong Tu | last post by:
How do I get system time in VC++ in the .net development environment?
28
17644
by: Nina | last post by:
I need to generate unique id for my application. Use system time to create id, which is the best fit, but I don't know how to do it. Please help. Thanks in advance for any input.
4
2294
by: Benny Van | last post by:
Hi all! I have a question regarding a windows operating system function: I was asked to write a small program for a homework to display the user name and computer name and the system time out to a...
2
5075
by: Mike | last post by:
I know, it is old question. Is there some new way to protect system time changes with C# 2.0? What is the best way based on your oppinion? Thanks, I appreciate your help. Mike
9
8406
by: Neil | last post by:
I'm using an Access MDB as a front end to a SQL 7 database. When I place the system time in a field in Access, it used the user's clock. I'd like to use the SQL Server system time, so that the...
2
2329
by: eneyardi | last post by:
I have a form that shows the current time, My problem is when users change the system time and it will update the time in the program. Is there any idea on how to avoid users change the system time?...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.