Current date and time in java

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTimeFormatter {

public static void main(String[] args) {
//I used SimpleDateFormat class for date and time format
SimpleDateFormat formatter = new SimpleDateFormat(“dd/MM/yyyy HH:mm:ss”);
//Here formatter is the reference object to class SimpleDateFormat
//I am using Date class to fetch the current date and time from server.
Date date = new Date();
//Here date is the reference object to class Date
System.out.println(formatter.format(date));
}
}

Leave a comment