How to format the Calendar month using String.format() in Java

1 Answer

0 votes
package javaapplication1;

import java.io.IOException;
import java.util.Calendar;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        try {

            Calendar cal = Calendar.getInstance();
            cal.set(2016, 10, 20);

            String s = String.format("Month: %1$tB %1$tb %1$tm", cal);
            System.out.println(s);
            
        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
Month: 11 Nov November
  
 */

 



answered Nov 20, 2016 by avibootz

Related questions

1 answer 228 views
1 answer 208 views
1 answer 177 views
1 answer 195 views
1 answer 225 views
1 answer 189 views
...