Java SimpleDateFormat format Calendar to String as 12:20

Description

Java SimpleDateFormat format Calendar 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 .  j a  v  a 2s. c  o m*/

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



PreviousNext

Related