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

1 Answer

0 votes
package javaapplication1;

import java.io.IOException;
import java.time.Instant;
import java.util.Calendar;
import java.util.Date;

public class JavaApplication1 {

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

        try {

            Calendar cal = Calendar.getInstance();
            cal.setTime(Date.from(Instant.now()));

            String s = String.format("Minute: %1$tM", cal);
            System.out.println(s);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
Minute: 57
  
 */

 



answered Nov 20, 2016 by avibootz

Related questions

1 answer 184 views
1 answer 203 views
1 answer 195 views
1 answer 216 views
1 answer 200 views
1 answer 173 views
...