Getting current date and time with Date

java.util.Date represents a specific instant in time, with millisecond precision.

Getting current date and time with Date

The example uses java.util.Date to get the current date-time and formats it with java.text.SimpleDateFormat.
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class JavaCurrentDateTimeDate {

    public static void main(String[] args) {

        Date now = new Date();

        DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        System.out.println(df.format(now));
    }
}
Output:
2019/07/11 17:30:13


Comments