Results 1 to 10 of 10
Thread: [SOLVED] time and date
- 05-27-2009, 02:04 PM #1
- 05-27-2009, 02:28 PM #2
Date and DateFormat
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-27-2009, 03:29 PM #3
honestly what do you mean date and dateformat???
i know nothing about dates in java.
if you could give me a simple example where i can read an input and convert it to time, date or something
- 05-27-2009, 03:52 PM #4
Honestly, if you're not even going to try to find out for yourself.Java Code:Date date = new Date();
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-27-2009, 04:13 PM #5
Java APIs...
Manfizy... when somebody mentions the name of a class and you don't know what it does, look in the Java API documentation:
Java Platform SE 6
If you need help with how to use it then look for some site that has examples...
Java Examples from The Java Developers Almanac 1.4
If that doesn't help, then you can google it:
java date example - Google Search
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 05-28-2009, 09:12 AM #6
Thanks pple for your help. i got it finally and i can display date and time in my program GUI
But another problem came up, my time is not updating and i want it synchronised with ths system clock such that the hours and minutes update as long as the program is running.
how can i do this?
any ideas?
-
how are you trying to update it? Are you using a Timer of some sort?
- 05-28-2009, 04:15 PM #8
Member
- Join Date
- Mar 2009
- Posts
- 25
- Rep Power
- 0
You can create a custom timer that will wait for however long you want it to, then update the time. This particular one will update every second (1000 milliseconds) until the program is shutdown. The Date() class is synchronised to your systems time (i.e. Thats the time it will use when you create a Date object without any parameters to the constructor).
Java Code:import java.util.Date; import java.util.GregorianCalendar; import javax.swing.JFrame; import javax.swing.JLabel; public class Clock extends JFrame { private JLabel dateLabel; public Clock() { dateLabel = new JLabel(new Date().toString()); add(dateLabel); pack(); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); while (true) { long timeToWait = new GregorianCalendar().getTimeInMillis() + 1000; while (new GregorianCalendar().getTimeInMillis() < timeToWait) ; dateLabel.setText(new Date().toString()); } } public static void main(String[] args) { new Clock(); } }
- 05-31-2009, 11:26 AM #9
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
- 06-02-2009, 11:13 AM #10
Similar Threads
-
Time and Date
By Manfizy in forum New To JavaReplies: 0Last Post: 05-27-2009, 12:58 PM -
Time-Date problem
By teo.danciu in forum New To JavaReplies: 5Last Post: 08-27-2008, 10:01 AM -
Formatting time and date
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:35 PM -
how to get the current date and time
By valery in forum New To JavaReplies: 1Last Post: 08-03-2007, 06:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks