top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are the different classes for formatting dates in Java?

+2 votes
537 views
What are the different classes for formatting dates in Java?
posted Jul 4, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

here two classes for formatting date in java: DateFormat and SimpleDateFormat.

The java.text.DateFormat class provides various methods to format and parse date and time in java in language independent manner. The DateFormat class is an abstract class. java.text.Format is the parent class and java.text.SimpleDateFormat is the subclass of java.text.DateFormat class.

answer Jul 4, 2017 by Ajay Kumar
0 votes

Classes for Formatting Dates

There are several classes for formatting dates. They are:
DateFormat: This is an abstract class, which formats and parses the dates and time in a language independent manner.
code snippet:
// this snippet formats the date//

String date = DateFormat.getDateTimeInstance (DateFormat.FULL,
                DateFormat.SHORT, locale). format(new Date());

DateFormat.Field: This is a nested class that is used as attribute keys in the AttributedCharacterIterator. The AttributedCharacterIterator allows iteration through both text and related attribute information. It is returned from DateFormat.formatToCharacterIterator and is also used as field identifiers in FieldPosition.

DateFormatSymbols: It is a public class, which encapsulates localizable date-time formatting data, such a names of months days of week and the time zone data. Both DateFormat class and SimpleDateFormat class use DateFormatSymbols to encapsulate localizable date-time formatting data information.

DateFormatter: The DateFormatter class formats the date as per the format of the current locale.

SimpleDateFormat: The SimpleDateFormat is a class that formats and parses dates in a locale-sensitive manner.
Code snippet:
//This snippet format the date as per the specified style//

SimpleDateFormat frmt = new SimpleDateFormat ("YYYY-MMM-DD", Locale.US);
answer Jul 4, 2017 by Pooja Singh
...