Results 1 to 3 of 3
  1. #1
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default Looking for a specific jcalendar command

    Hey, i got a dynamic clock in my program, but the time shows like this:
    1:10:5

    Where i would want it to show like this:
    01:10:05

    (i want it to always be 2 digits)

    heres the code:
    Java Code:
                         int second = cal.get(Calendar.SECOND);
                         int minute = cal.get(Calendar.MINUTE);
                         int hour = cal.get(Calendar.HOUR);
                         time_txt.setText(hour + ":" + (minute) + ":" + second);

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default Re: Looking for a specific jcalendar command

    Do you lack the imagination to come up with something simple such as this:

    Java Code:
    String display(int x) {
       if (x < 10) return "0"+x;
       return ""+x;
    }
    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Looking for a specific jcalendar command

    What you probably will like is the SimpleDateFormat class. There you may call e.g. SimpleDateFormat.format( Date ) and there you go.

    Java Code:
    SimpleDateFormat myDate = new SimpleDateFormat("HH:mm:ss");
    time_txt.setText( myDate.format( cal.getDate() ) );
    Last edited by Sierra; 12-15-2012 at 01:04 PM.
    I like likes!

Similar Threads

  1. Can i change jCalendar language?
    By iNko in forum NetBeans
    Replies: 4
    Last Post: 12-09-2012, 05:35 PM
  2. Binding jDateChooser (from jCalendar) date to filter table
    By madcloud in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 03-06-2011, 02:56 PM
  3. multi-sélection dans un JCalendar
    By mcherkao in forum AWT / Swing
    Replies: 1
    Last Post: 01-09-2011, 04:38 AM
  4. Jcalendar Help
    By simmi in forum AWT / Swing
    Replies: 3
    Last Post: 08-14-2009, 04:09 PM
  5. Replies: 2
    Last Post: 11-08-2008, 10:40 AM

Posting Permissions

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