Java Calendar format to String as 12:20

Description

Java Calendar format to String as 12:20

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) {
        System.out.println(stringForCurrentTime());
    }/*from w w  w  . jav  a2  s.  c  om*/

    public static String stringForCurrentTime() {
        return new SimpleDateFormat("hh:mm").format(Calendar.getInstance()
                .getTime());
    }
}



PreviousNext

Related