Often, we wish to Format the Date and Time information into a given format, either for displaying the same to the end user or for further processing.
Java contains formatting classes which can be used to format a date into a desired format. The most commonly used class for formatting dates is the
SimpleDateFormat class.
The SimpleDateFormat class takes format string as input to its constructor and returns a format object which can then be used to format
Date objects. Calling the
format() method of the
SimpleDateFormat object will return a string that contains the formatted representation of the Date that is passed into the method as a parameter.
The table below contains Time and Date Format Codes which can be used to format the Date Object.