LogRecord setInstant() method in Java with Examples Last Updated : 23 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The setInstant() method of java.lang.reflect.LogRecord is used to set this instant that the event occurred this is helpful to record logging events instant. An arithmeticException will be thrown if the given instant represents a point on the timeline too far in the future or past to fit in long milliseconds and nanoseconds adjustment. Syntax: public void setInstant(Instant instant) Parameters: This method accepts instant which is the instant that the event occurred. Return: This method returns nothing. Exception: This method will throw following exceptions: NullPointerException - if instant is null. ArithmeticException - if numeric overflow would occur while calling instant.toEpochMilli(). Below programs illustrate setInstant() method: Program 1: Java // Java program to illustrate // setInstant() 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 a Instant object Instant instant = Instant.parse("2018-12-30T19:34:50.63Z"); // Create LogRecord object LogRecord logRecord = new LogRecord( Level.parse("800"), "Hi Logger"); // set Instant time logRecord.setInstant(instant); System.out.println( "Event Time " + logRecord.getInstant() .toString()); } } Output: Event Time 2018-12-30T19:34:50.630Z Program 2: Java // Java program to illustrate // setInstant() 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 a Instant object Instant instant = Instant.now(); // Create LogRecord object LogRecord logRecord = new LogRecord( Level.parse("800"), "GFG Logger"); // set Instant time logRecord.setInstant(instant); System.out.println0( "Event Time " + logRecord.getInstant() .toString()); } } Output: Event Time 2019-10-20T19:32:50.818428ZEvent Time 09 Sep 2001 07:16:39:900 +0530 References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/LogRecord.html#setInstant(java.time.Instant) Comment More infoAdvertise with us Next Article LogRecord setInstant() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-LogRecord java.util.logging package Practice Tags : Java Similar Reads LogRecord setThrown() method in Java with Examples The setThrown() method of java.util.logging.LogRecord is used to a throwable associated with the log event.This is used to log Exceptions in the logRecord that can be used for logging messages. Syntax: public void setThrown(Throwable thrown) Parameters: This method accepts thrown as a parameter whic 2 min read LogRecord setMillis() method in Java with Examples The setMillis() method of java.util.logging.LogRecord is used to set the event time in LogRecord.This event time has unit in MilliSeconds since 1970.Syntax: public void setMillis(long millis) Parameters: This method accepts millis as parameter which is event time in milli-seconds since 1970Return: T 2 min read LogRecord setMessage() method in Java with Examples The setMessage() method of java.util.logging.LogRecord is used to set the "raw" log message, before localization or formatting for this LogRecord object.we can also set null as raw message. Syntax: public void setMessage(String message) Parameters: This method accepts message which is the raw messag 1 min read LogRecord setThreadID() method in Java with Examples The setThreadID() method of java.util.logging.LogRecord is used to set an identifier for the thread where the message originated. This method is helpful to identify thread which generates the logger message. Syntax: public void setThreadID(int threadID) Parameters: This method accepts threadID which 2 min read LogRecord setLevel() method in Java with Examples The setLevel() method of java.util.logging.LogRecord is used to set the level of logging message, for example Level.INFO for this LogRecord Object. Syntax: public void setLevel(Level level) Parameters: This method accepts level which is the logging message level. Return: This method returns nothing. 1 min read Like