Open In App

DateFormat getTimeInstance() Method in Java with Examples

Last Updated : 24 Jan, 2022
Comments
Improve
Suggest changes
2 Likes
Like
Report

DateFormat class of java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time.

Note: DateFormat class extends Format class that means it is a subclass of Format class. Since DateFormat class is an abstract class, therefore, it can be used for date/time formatting subclasses, which format and parses dates or times in a language-independent manner.  

Package-view:

java.text Package
    DateFormat Class
        getTimeInstance() Method

getTimeInstance() Method of DateFormat class in Java is used to get the time format. This time formatter comes with a default formatting style for a default locale.

Syntax: 

public static final DateFormat getTimeInstance()

Parameter: The method does not take any parameters.

Return Type: The method returns a time formatted in a particular format.

Example 1:


Output
Object: java.text.SimpleDateFormat@8400729
6:39:49 AM

Example 2:


Output
The Original: 01/11/2022
Object: java.text.SimpleDateFormat@8400729
6:45:24 AM

Next Article
Practice Tags :

Similar Reads