Date Difference
This example learns how to make the difference between two dates and how to convert milliseconds into seconds, seconds into minutes, minutes into hours, hours into days.
Here we are using Calendar, an abstract base class that extends Object class and makes a difference between a Date object and a set of integer fields. Calendar class provides a getInstance() method for returning a Calendar object whose time fields have been initialized with the current date and time.
The methods used:
setTimeInMillis(long millis): This method is used to set current time in calendar object.
Here we are using Calendar, an abstract base class that extends Object class and makes a difference between a Date object and a set of integer fields. Calendar class provides a getInstance() method for returning a Calendar object whose time fields have been initialized with the current date and time.
The methods used:
setTimeInMillis(long millis): This method is used to set current time in calendar object.
getInstance(): This method is used to get a calendar using the default time zone, locale and current time.
The code of the program is given below:
import java.util.Calendar; |
The output of the program is given below:
C:\rajesh\kodejava>javac DateDifferent.java C:\rajesh\kodejava>java DateDifferent The Date Different Example
Time in milliseconds: 14860800000 milliseconds.
Time in seconds: 14860800 seconds.
Time in minutes: 247680 minutes.
Time in hours: 4128 hours.
Time in days: 172 days. |
No comments:
Post a Comment