How to format the date in particular pattern
This tip will show the use of SimpleDateFormat class. This class format the date in to the desired pattern. This sample program format the current system date to the format "dd/MM/yyyy".
Code:
import java.text.SimpleDateFormat;
import java.util.Date;
public class FormatterExp {
public static void main(String[] args) {
// pattern to be used in formatting the date
String pattern = "dd/MM/yyyy";
SimpleDateFormat sdf = new SimpleDateFormat();
// apply the pattern to the SimpleDateFormat class
sdf.applyPattern(pattern);
// Format and print the date in the desired format.
System.out.println("Formatted date :- " + sdf.format(new Date()));
}
}