java.time.LocalTime.ofNanoOfDay() Method Example



Description

The java.time.LocalTime.ofNanoOfDay(long nanoOfDay) method obtains an instance of LocalTime from a nanos-of-day value.

Declaration

Following is the declaration for java.time.LocalTime.ofNanoOfDay(long nanoOfDay) method.

public static LocalTime ofNanoOfDay(long nanoOfDay)

Parameters

nanoOfDay − the nano of day, from 0 to 24 * 60 * 60 * 1,000,000,000 - 1

Return Value

the local time, not null.

Exceptions

DateTimeException − if the nanos of day value is invalid.

Example

The following example shows the usage of java.time.LocalTime.ofNanoOfDay(long nanoOfDay) method.

package com.tutorialspoint;

import java.time.LocalTime;
import java.time.ZoneOffset;

public class LocalTimeDemo {
   public static void main(String[] args) {
 
      LocalTime time = LocalTime.ofNanoOfDay(50000);
      System.out.println(time);  
   }
}

Let us compile and run the above program, this will produce the following result −

00:00:00.000050
Advertisements