
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Time Functions in Java
Java provides the Date class available in java.util package, this class encapsulates the current date and time. The time functions can be accessed from the java.util.Date class. This represents an instance of time with millisecond precision.
One of the time function in Java is the getTime() function. It returns the number of milliseconds that have passed since January 1, 1970, 00:00:00 GMT. A program that demonstrates this is given as follows −
Example
import java.util.*; public class Example { public static void main(String[] args) { Date d = new Date(95, 7, 15); long num = d.getTime(); System.out.println("From the date 1-1-1970 to the date 15-07-1995, " + num + " milliseconds have passed."); } }
Output
From the date 1-1-1970 to the date 15-07-1995, 808444800000 milliseconds have passed.
Now let us understand the above program.
First, a date is created. Then the function getTime() is used to find the number of milliseconds that have passed since January 1, 1970, 00:00:00 GMT. Then this is displayed. The code snippet that demonstrates this is given as follows −
Date d = new Date(95, 7, 15); long num = d.getTime(); System.out.println("From the date 1-1-1970 to the date 15-07-1995, " + num + " milliseconds have passed.");
- Related Questions & Answers
- Time Functions in C#
- Time Functions in Python?
- Date and Time Functions in DBMS
- Exclusive Time of Functions in C++
- Trigonometric Functions in Java
- Log functions in Java
- Iterator Functions in Java
- Calendar Functions in Java
- Mathematical Functions in Java
- Are there inline functions in Java?
- What are variadic functions in Java?
- Convert string of time to time object in Java
- Laplace Transform of Periodic Functions (Time Periodicity Property of Laplace Transform)
- Measuring elapsed time in Java
- Get elapsed time in Java
Advertisements