How to get the Current Time in Milliseconds using either Date or Calendar classes



This example shows how to get the current time in milliseconds. It can be done in two ways, either directly through the Date class or by using the Calendar class.
If using the Calendar class we actually are using the Date class too, since the method getTime() in the Calendar class returns a Date object.
The method getTime() in the Date class returns the time in milliseconds as datatype long. That’s why it is called twice using the Calendar class.
The milliseconds is the number of milliseconds elapsed since January 1, 1970, 00:00:00 GMT.







Search for more Java info on this site here:
Custom Search


Any thoughts or questions?