Java.getTime() Method

Learn via video course
FREE
View all courses
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Topics Covered

Overview

getTime() method of Java Date Class present in java.util package returns the number of milliseconds since Jan 1 of the year 1970, 00:00:00 GTM (Greenwich Mean Time) which is performed by creating the Date object. This method can be used to assign a date and by using java.getTime() method we can return the number of milliseconds since Jan 1, 1970.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax of Java.getTime()

Parameters of Java.getTime()

This method does not accept any parameters.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Return Value of Java.getTime()

This method returns the number of milliseconds since January 1, 1970, 00:00:00 GTM (Unix Epoch).

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Exceptions of Java.getTime()

This method does not throw any Runtime Exceptions.

Example

Below is an example of java.getTime() method from Date class: The below given java program implements the java.getTime() method which is present in Date class, we have tentatively assumed the Date to be 20thMarch,200120^{th} March, 2001.

Output:

Explanation Using the java.getTime() method from Date class we have obtained a number of milliseconds from Jan 1, 1970 to the given date i.e, March 20, 2001, is 60945868800000 milliseconds.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

What is java.getTime()?

java.getTime() method of Java Date Class in util package in Java returns the number of milliseconds from Jan 1, 1970, in form of 00:00:00 GTM. This also returns the present date by creating the Date object using the getTime() method. This method does not accept any parameters and does not throw any Runtime Exceptions.

More Examples:

Some more examples of java.getTime() method using getInstance() method of Calendar class in Java. Using the getInstance() method we can set a date up to which the number of milliseconds has to be counted since January 1, 1970. This is clearly shown in the below implementation:

Output:

Explanation Using the java.getTime() method from Date class we have obtained number of milliseconds since Jan 1, 1970, to the given date i.e, November 1, 2001, is 1004577411672 milliseconds.


The second example for a better understanding of the getTime() method in Java where the Date considered is October 12, 2020 is:

Output:

Explanation Using the java.getTime() method from the Date class we have obtained a number of milliseconds from Jan 1, 1970 to the given date i.e, October 12, 2020, is 1602465375847 milliseconds.

Conclusion:

  • java.getTime() method is from the Date class which is present in the util package.
  • This method does not accept any parameters.
  • This method does not throw any Runtime Exceptions.
  • This method returns the number of milliseconds since Jan 1, 1970.