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

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">