Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By JosAH

Thread: Error: Using Calendar

  1. #1
    bboyinmartin is offline Member
    Join Date
    Jul 2013
    Posts
    18
    Rep Power
    0

    Angry Error: Using Calendar

    public static void main(String[] args) {

    Calendar c = Calendar.getInstance();
    System.out.format( "%tm" + "/" + "%td" + "/" + "%tY", c);


    }

    OUTPUT:
    07/Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier 'td'
    at java.util.Formatter.format(Unknown Source)
    at java.io.PrintStream.format(Unknown Source)
    at something.main(something.java:9)



    Why does this result error?
    Formatting Numeric Print Output (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
    This website shows that those converters ARE right.
    Am I doing something wrong?

  2. #2
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    393
    Rep Power
    6

    Default Re: Error: Using Calendar

    You need to have as many values after the String as you have converters in the String. Right now, you're only supplying data to %tm, and there's no data for %td and %tY.

  3. #3
    bboyinmartin is offline Member
    Join Date
    Jul 2013
    Posts
    18
    Rep Power
    0

    Default Re: Error: Using Calendar

    Oh okay. Problem solved. I just had to put two more c's. Thanks!

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,292
    Blog Entries
    7
    Rep Power
    24

    Default Re: Error: Using Calendar

    Quote Originally Posted by bboyinmartin View Post
    Oh okay. Problem solved. I just had to put two more c's. Thanks!
    That is not really needed (although it works), you can use the argument indexing option:

    Java Code:
    System.out.format( "%1$tm" + "/" + "%1$td" + "/" + "%1$tY", c);
    The '$1' thingy tells the formatter to use the first argument (and is not really needed here for the month specification).

    kind regards,

    Jos
    DarrylBurke likes this.
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Calendar now = Calendar.getInstance()
    By volkvanmyn25 in forum New To Java
    Replies: 3
    Last Post: 10-31-2011, 11:25 PM
  2. Replies: 4
    Last Post: 09-21-2011, 04:39 PM
  3. JSF Calendar Component JS error
    By zazzko in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 02-11-2009, 08:33 PM
  4. Calendar bug?
    By Stigvig in forum Advanced Java
    Replies: 14
    Last Post: 02-08-2009, 10:56 AM
  5. Replies: 1
    Last Post: 08-07-2007, 07:53 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
  •