
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java 8 Clock millis Method
The current instance of the clock in milliseconds can be obtained using the method millis() in the Clock Class in Java. This method requires no parameters and it returns the current instant of the clock in milliseconds. If the instance cannot be obtained for some reason, then the DateTimeException is thrown.
A program that demonstrates this is given as follows −
Example
import java.time.*; public class Demo { public static void main(String[] args) { Clock c = Clock.systemDefaultZone(); long ms = c.millis(); System.out.println("The clock is: " + c); System.out.println("The instance in milliseconds is: " + ms); } }
Output
The clock is: SystemClock[Etc/UTC] The instance in milliseconds is: 1549529350787
Now let us understand the above program.
The method millis() is used to obtain the current instance of the clock in milliseconds and then this is displayed. A code snippet that demonstrates this is as follows −
Clock c = Clock.systemDefaultZone(); long ms = c.millis(); System.out.println("The clock is: " + c); System.out.println("The instance in milliseconds is: " + ms);
Advertisements