Java Date and Time

Java Date and Time


Date, and Time In Java
  • The Date class encapsulates the current date and time. Before beginning our examination of Date, it is important to point out that it has changed substantially from its original version defined by Java 1.0. When Java 1.1 was released.
  • The Date class encapsulates the current date and time. Before beginning our examination of Date, it is important to point out that it has changed substantially from its original version defined by Java 1.0. When Java 1.1 was released.
Date supports the following constructors -
Date( )
Date(long millisec)
Example -
Output -  here is the sample outcome
Note - 
The abstract Calendar class provides a set of methods that allows you to convert a time in milliseconds to a number of useful components. Some examples of the type of information that can be provided are year, month, day, hour, minute, and second.
Formatting Time and Date -
  • One of the more powerful conversion specifiers is %t.
  • It lets you format time and date information. 
  •  The %t specifier works a bit differently than the others because it requires the use of a suffix to describe the portion and precise format of the time or date desired.
  • The suffixes are shown in Table 18-13. For example, to display minutes, you would use %tM, where M indicates minutes in a two-character field. The argument corresponding to the %t specifier must be of type Calendar, Date, Long, or long.
Let us see an example which describe some formates -
Example -
Output -