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

    Default Looking for a specific jcalendar command

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

    Where i would want it to show like this:

    (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
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    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;
    I have the stamina of a seal; I lie on the beach instead of running on it.

  3. #3
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Rep Power

    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 02: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, 06: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, 03:56 PM
  3. multi-sélection dans un JCalendar
    By mcherkao in forum AWT / Swing
    Replies: 1
    Last Post: 01-09-2011, 05: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, 11: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