Get Today's Date
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Main {
public void convertDateToString() {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
try {
System.out.println("Today: " + dateFormat.format(calendar.getTime()));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Main().convertDateToString();
}
}
The output from the code above prints the current date.
0 comments: