How to get time now hours, minutes, seconds Each one separately code example

Example: How to get time now hours, minutes, seconds Each one separately

package com.zetcode;

import java.time.LocalTime;

public class JavaLocalTimeParts {

    public static void main(String[] args) {

        LocalTime time = LocalTime.now();

        System.out.printf("Hour: %s%n", time.getHour());
        System.out.printf("Minute: %s%n", time.getMinute());
        System.out.printf("Second: %s%n", time.getSecond());
    }
}

	//The getHour() gets the hour part, the getMinute() gets the minute part, and the getSecond() the second part of the LocalTime.
	
	//This is the output.
	//Hour: 18
	//Minute: 25
	//Second: 55

Tags:

Java Example