Date provides you a specific instant in
time( millisecond) precision. This class enabled you to interprets
allowed dates as year, month, day, hour, minute, and second values and
date formatting and parsing of date string.
In this Tutorial we want to describe you a code that helps you in understanding in a Getting Time and Date. For this we have a class 'GetTimeAndDate'.Inside the main method we declared a string variable, formatter and instantiate a date class.
1)Date ( ) - This is used to instantiate the date class and allocate the memory to a date object, such that it represent the time allocated to it in the nearest millisecond.
SimpleDateFormat- is a formatting concrete class that
helps you in parsing date in a locale-sensitive manner. This allows you to
format (date -> text), parsing (text -> date), and normalization.
3)format(date) -This method return you a formatted object to a string and stored in a string variable s.
Finally the System.out .println print the Date, Time and date-time altogether.GetTimeAndDate.java
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial