xxxxxxxxxx
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateExample {
public static void main(String[] args) {
// Creating a SimpleDateFormat object with the desired date format
DateFormat desiredFormat = new SimpleDateFormat("dd/MM/yyyy");
// Creating a Date object representing the current date
Date currentDate = new Date();
// Formatting the date using the desired format
String formattedDate = desiredFormat.format(currentDate);
// Printing the formatted date
System.out.println("Formatted date: " + formattedDate);
}
}
xxxxxxxxxx
String dateString = "27-AUG-2019";
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy");
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
try {
LocalDate date = LocalDate.parse(dateString, inputFormatter);
String formattedDate = date.format(outputFormatter);
System.out.println("Tanggal dalam format baru: " + formattedDate);
} catch (Exception e) {
e.printStackTrace();
}