GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection
  • Introduction3 min read
  • Variables2 min read
  • Data Types7 min read
  • Operators7 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — java.time.LocalTime Class in Java - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection

java.time.LocalTime Class in Java

Last Updated : 4 Nov, 2026

The LocalTime class, available in the java.time package, represents a time without date and timezone. Introduced in Java 8, it is part of the modern Date-Time API and is used to store and manipulate time values such as meeting schedules, alarms, business hours, and event timings.

  • Represents only hour, minute, second, and nanosecond.
  • Provides methods for formatting, parsing, and comparing time values.
  • Immutable and thread-safe.

Declaration Of java.time.LocalTime Class

public final class LocalTime
extends Object
implements Temporal, TemporalAdjuster,
Comparable<LocalTime>, Serializable

Approach

  1. Import the java.time.LocalTime class.
  2. Create a LocalTime object using methods such as now(), of(), or parse().
  3. Perform operations like formatting, comparison, addition, or subtraction.
  4. Display the result using System.out.println().

Example: Program to illustrate LocalTime Class

Java
// Importing LocalDateTime class from
// java.time package
import java.time.LocalTime;

// Main Class
public class GFG {

    // Main driver method
    public static void main(String args[])
    {

        // Creating an object of LocalTime class by
        // declaring a variable to store LocalTime
        LocalTime ltime = LocalTime.now();

        // Print and display the LocalTime value
        System.out.println("Local time value : " + ltime);
    }
}

Output
Local time value : 06:20:52.986897

Explanation: The LocalTime.now() method returns the current system time. The program creates a LocalTime object and prints the current time, including hours, minutes, seconds, and nanoseconds.

Example: Program to illustrate LocalTime where plusMethod() is illustrated

Java
// Importing LocalTime class from
// java.time package
import java.time.LocalTime;

// Main Class
public class GFG {

    // main driver method
    public static void main(String args[])
    {
        // Creating an object of LocalTime Class by
        // declaring a variable to store LocalTime
        LocalTime ltime = LocalTime.now();

        // Now plusMinute() will add up minutes to the
        // LocalTime
        LocalTime time3 = ltime.plusMinutes(120);

        // Display the time using object of class
        System.out.println("Time : " + time3);
    }
}

Output
Time : 08:34:59.135137

Explanation: The plusMinutes(120) method adds 120 minutes (2 hours) to the current time and returns a new LocalTime object. The original time remains unchanged because LocalTime is immutable.

Advantages of LocalTime

The LocalTime class provides a simple and reliable way to work with time without including date or time zone information.

  • Provides methods for performing time-based calculations and comparisons.
  • Creates new LocalTime objects instead of modifying existing instances, ensuring immutability.
  • Supports different time formats using DateTimeFormatter.
  • Useful for applications that require time handling without date or time zone information.

Commonly Used Methods of LocalTime

MethodDescription
now()Returns the current time using the system clock and default time zone.
of(int hour, int minute)Creates a LocalTime with the specified hour and minute.
parse(CharSequence text)Creates a LocalTime by parsing a time string.
getHour()Returns the hour of the day.
getMinute()Returns the minute of the hour.
getSecond()Returns the second of the minute.
plusHours(long hours)Returns a copy with the specified number of hours added.
plusMinutes(long minutes)Returns a copy with the specified number of minutes added.
minusHours(long hours)Returns a copy with the specified number of hours subtracted.
minusMinutes(long minutes)Returns a copy with the specified number of minutes subtracted.
isBefore(LocalTime other)Checks whether this time is before another time.
isAfter(LocalTime other)Checks whether this time is after another time.
format(DateTimeFormatter formatter)Formats the time using the specified formatter.
Comment

Explore

    Basics
    • Introduction3 min read
    • Variables2 min read
    • Data Types7 min read
    • Operators7 min read
    • Decision Making5 min read
    • Methods7 min read
    • Arrays7 min read
    • Strings5 min read
    OOP & Interface
    • Introduction6 min read
    • Constructors6 min read
    • Encapsulation3 min read
    • Inheritance8 min read
    • Polymorphism5 min read
    • Abstraction5 min read
    • Interfaces8 min read
    Collections
    • Collection class9 min read
    • Collection Interface5 min read
    • List Interface8 min read
    • Set Interface5 min read
    • Queue Interface5 min read
    • Map Interface in Java6 min read
    • Iterator4 min read
    Advance Java Concepts
    • Exception handling6 min read
    • Java Multithreading Tutorial3 min read
    • Synchronization in Java9 min read
    • File handling6 min read
    • Method References3 min read
    • Java 8 Stream Tutorial7 min read
    • Memory Management4 min read
    • Garbage Collection in Java6 min read
    • Networking6 min read
    • JDBC5 min read
    Practice Java
    • Interview Questions15+ min read
    • Programs6 min read
    • Practice Problems5 min read
    • Quiz1 min read
    • Project Ideas15+ min read
    Courses
    • Java Backend Course2 min read
    • Placement 360 Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.