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

1 Answer

0 votes
import java.io.IOException;
import java.util.Calendar;
 
class Main {
    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: November Nov 11

*/

 



answered Nov 20, 2016 by avibootz
edited Aug 22 by avibootz

Related questions

1 answer 313 views
1 answer 296 views
1 answer 275 views
1 answer 298 views
1 answer 340 views
1 answer 293 views
...