Results 1 to 10 of 10
  1. #1
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Default [SOLVED] time and date

    hi pple,
    how can i capture system date and time and probably display it on a panel or something??

    your help is highly appreciated

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Date and DateFormat
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Default

    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

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Java Code:
    Date date = new Date();
    Honestly, if you're not even going to try to find out for yourself.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default 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,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  6. #6
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Default

    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?

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    how are you trying to update it? Are you using a Timer of some sort?

  8. #8
    Join Date
    Mar 2009
    Posts
    25
    Rep Power
    0

    Default

    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();
       }
    }

  9. #9
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Manfizy, have a look at this. :)
    I die a little on the inside...
    Every time I get shot.

  10. #10
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

Similar Threads

  1. Time and Date
    By Manfizy in forum New To Java
    Replies: 0
    Last Post: 05-27-2009, 12:58 PM
  2. Time-Date problem
    By teo.danciu in forum New To Java
    Replies: 5
    Last Post: 08-27-2008, 10:01 AM
  3. Formatting time and date
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:35 PM
  4. how to get the current date and time
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •