Wednesday, July 3, 2024
HomeLanguagesJavaTimeUnit toMinutes() method in Java with Examples

TimeUnit toMinutes() method in Java with Examples

The toMinutes() method of TimeUnit Class is used to get the time represented by the TimeUnit object, as the number of Minutes, since midnight UTC on the 1st January 1970.

Syntax:  

public long toMinutes(long duration)

Parameters: This method accepts a mandatory parameter duration which is the duration in milliSeconds.

Return Value: This method returns the converted duration as Minutes.

Below program illustrate the implementation of TimeUnit toMinutes() method:

Program 1:

Java




// Java program to demonstrate
// toMinutes() method of TimeUnit Class
 
import java.util.concurrent.*;
import java.util.Date;
 
class GFG {
    public static void main(String args[])
    {
        // Get current time in milliseconds
        long timeInMilliSec = new Date().getTime();
 
        // Create a TimeUnit object
        TimeUnit time = TimeUnit.MILLISECONDS;
 
        // Convert milliseconds to Minutes
        // using toMinutes() method
        System.out.println("Time " + timeInMilliSec
                           + " milliSeconds in Minutes = "
                           + time.toMinutes(timeInMilliSec));
    }
}


Output: 

Time 1539585683206 milliSeconds in Minutes = 25659761

 

Program 2:

Java




// Java program to demonstrate
// toMinutes() method of TimeUnit Class
 
import java.util.concurrent.*;
import java.util.Calendar;
 
class GFG {
    public static void main(String args[])
    {
        // Get current time in milliseconds
        long timeInMilliSec = Calendar
                                  .getInstance()
                                  .getTimeInMillis();
 
        // Create a TimeUnit object
        TimeUnit time = TimeUnit.MILLISECONDS;
 
        // Convert milliseconds to Minutes
        // using toMinutes() method
        System.out.println("Time " + timeInMilliSec
                           + " milliSeconds in Minutes = "
                           + time.toMinutes(timeInMilliSec));
    }
}


Output: 

Time 1539585685664 milliSeconds in Minutes = 25659761

 

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments