Open In App

LogRecord setMillis() method in Java with Examples

Last Updated : 09 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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 1970
Return: This method returns nothing.
Below programs illustrate setMillis() method: 
Program 1: 
 

Java




// Java program to illustrate setMillis() method
 
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
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");
 
        // set event time
        logRecord.setMillis(999999999900L);
 
        // get event time and convert it into date
        DateFormat simple
            = new SimpleDateFormat(
                "dd MMM yyyy HH:mm:ss:SSS Z");
 
        Date result
            = new Date(logRecord.getMillis());
 
        System.out.println("Event Time "
                           + simple.format(result));
    }
}


Output: 

Event Time 09 Sep 2001 01:46:39:900 +0000

 

Program 2: 
 

Java




// Java program to illustrate setMillis() method
 
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
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"),
            "GFG Logger");
 
        // set event time
        logRecord.setMillis(9632736138L);
 
        // get event time and convert it into date
        DateFormat simple
            = new SimpleDateFormat(
                "dd MMM yyyy");
 
        Date result
            = new Date(logRecord.getMillis());
 
        System.out.println("Event Date: "
                           + simple.format(result));
    }
}


Output: 

Event Date: 22 Apr 1970

 

References: https://docs.oracle.com/javase/8/docs/api/java/util/logging/LogRecord.html#setMillis-long-
 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads