LogRecord getInstant() method in Java with Examples

The getInstant() method of java.lang.reflect.LogRecord is used to get this instant that the event occurred this is helpful to record logging events instant.

Syntax:

public Instant getInstant()

Parameters: This method accepts nothing.

Return: This method returns the instant that the event occurred.

Below programs illustrate getInstant() method:
Program 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate getInstant() method
  
import java.time.Instant;
import java.util.logging.Level;
import java.util.logging.LogRecord;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("800"),
            "Hi Logger");
        logRecord
            .setInstant(
                Instant.parse(
                    "1994-04-12T11:54:23.89Z"));
  
        // get the instant time
        Instant instant = logRecord.getInstant();
  
        System.out.println("Event Time = "
                           + instant.toString());
    }
}

chevron_right


Output:

Event Time = 1994-04-12T11:54:23.890Z

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate getInstant() method
  
import java.time.Instant;
import java.util.logging.Level;
import java.util.logging.LogRecord;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("800"),
            "Hi Logger");
        logRecord.setInstant(Instant.now());
  
        // get the instant time
        Instant instant = logRecord.getInstant();
  
        System.out.println("Event Time = "
                           + instant.toString());
    }
}

chevron_right


Output:

Event Time = 2019-10-20T19:41:57.803594Z

References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/LogRecord.html#getInstant()

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.