Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Duration toDays() method in Java with Examples
Next article icon

Duration toMillis() method in Java with Examples

Last Updated : 26 Nov, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report

The toMillis() method of Duration Class in java.time package is used get the value of this duration in number of milli-seconds.

Syntax:

  public long toMillis()  

Parameters: This method do not accepts any parameter.

Return Value: This method returns a long value which is the number of milli-seconds in this duration.

Below examples illustrate the Duration.toMillis() method:

Example 1:




// Java code to illustrate toMillis() method
  
import java.time.Duration;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Duration using parse() method
        Duration duration
            = Duration.parse("P2DT3H4M");
  
        System.out.println("Duration: "
                           + duration);
  
        // Get the number of milli-seconds
        // using toMillis() method
        System.out.println(duration.toMillis());
    }
}
 
 
Output:
  Duration: PT51H4M  183840000  

Example 2:




// Java code to illustrate toMillis() method
  
import java.time.Duration;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Duration using ofMillis() method
        Duration duration
            = Duration.ofMillis(10);
  
        System.out.println("Duration: "
                           + duration);
  
        // Get the number of milli-seconds
        // using toMillis() method
        System.out.println(duration.toMillis());
    }
}
 
 
Output:
  Duration: PT0.01S  10  

Reference: https://docs.oracle.com/javase/9/docs/api/java/time/Duration.html#toMillis–



Next Article
Duration toDays() method in Java with Examples

C

code_r
Improve
Article Tags :
  • Java
  • Java-Duration
  • Java-Functions
  • Java-time package
Practice Tags :
  • Java

Similar Reads

  • Duration toMillisPart() method in Java with Examples
    The toMillisPart() method of Duration Class in java.time package is used get the value of this duration in number of milli-seconds by dividing the number of nanoseconds by 1, 000, 000. Syntax: public long toMillisPart() Parameters: This method do not accepts any parameter. Return Value: This method
    1 min read
  • Duration ofMillis(long) method in Java with Examples
    The ofMillis(long) method of Duration Class in java.time package is used to get a duration in a 1 milliSecond format. Syntax: public static Duration ofMillis(long milliSeconds) Parameters: This method accepts a parameter milliSeconds which is the number of milliSeconds. It can be positive or negativ
    1 min read
  • Duration toMinutes() method in Java with Examples
    The toMinutes() method of Duration Class in java.time package is used get the value of this duration in number of minutes. Syntax: public long toMinutes() Parameters: This method do not accepts any parameter. Return Value: This method returns a long value which is the number of minutes in this durat
    1 min read
  • Duration toDays() method in Java with Examples
    The toDays() method of Duration Class in java.time package is used get the value of this duration in number of days. Syntax: public long toDays() Parameters: This method do not accepts any parameter. Return Value: This method returns a long value which is the number of days in this duration. Below e
    1 min read
  • Duration toHours() method in Java with Examples
    The toHours() method of Duration Class in java.time package is used get the value of this duration in number of hours. Syntax: public long toHours() Parameters: This method do not accepts any parameter. Return Value: This method returns a long value which is the number of hours in this duration. Bel
    1 min read
  • Duration toNanos() method in Java with Examples
    The toNanos() method of Duration Class in java.time package is used get the value of this duration in number of nano-seconds. Syntax: public long toNanos() Parameters: This method do not accepts any parameter. Return Value: This method returns a long value which is the number of nano-seconds in this
    1 min read
  • Duration plusMillis(long) method in Java with Examples
    The plusMillis(long) method of Duration Class in java.time package is used to get an immutable copy of this duration with the specified number of milli-seconds added, passed as the parameter. Syntax: public Duration plusMillis(long numberOfMillis) Parameters: This method accepts a parameter numberOf
    1 min read
  • Duration toMinutesPart() method in Java with Examples
    The toMinutesPart() method of Duration Class in java.time package is used get the value of this duration in number of minutes by dividing the number of minutes in a hour. Syntax: public long toMinutesPart() Parameters: This method do not accepts any parameter. Return Value: This method returns a lon
    1 min read
  • Duration toString() method in Java with Examples
    The toString() method of Duration Class in java.time package is used to get the String value of this duration. This String is in the ISO-8601 format. Syntax: public String toString() Parameters: This method do not accepts any parameter. Return Value: This method returns a String value which is the S
    1 min read
  • Duration minusMillis(long) method in Java with Examples
    The minusMillis(long) method of Duration Class in java.time package is used to get an immutable copy of this duration with the specified number of milli-seconds subtracted, passed as the parameter. Syntax: public Duration minusMillis(long numberOfMillis) Parameters: This method accepts a parameter n
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences