get current Time String by Format - Java java.util

Java examples for java.util:Time Format

Description

get current Time String by Format

Demo Code


//package com.java2s;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) {
        String format = "yyyy-MM-dd";
        System.out.println(getTimeStrFormat(format));
    }/* ww  w  .  ja  v  a 2 s .  c  om*/

    public static String getTimeStrFormat(String format) {
        DateFormat df = new SimpleDateFormat(format);
        Calendar calendar = Calendar.getInstance();
        return df.format(calendar.getTime());

    }
}

Related Tutorials