Saturday, October 11, 2025
HomeLanguagesJavaLogRecord getMillis() method in Java with Examples

LogRecord getMillis() method in Java with Examples

The getMillis() method of java.lang.reflect.LogRecord is used to get the event time in LogRecord.This event time has unit in MilliSeconds since 1970.

Syntax:

public long getMillis()

Parameters: This method accepts nothing.

Return: This method returns truncated event time in millis since 1970.

Below programs illustrate getMillis() method:
Program 1:




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


Output:

Event Time 09 Sep 2001 07:16:39:900 +0530

Program 2:




// Java program to illustrate
// getMillis() 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("600"),
            "GFG Logger");
        logRecord.setMillis(9632736138L);
  
        // get event time
        long millis = logRecord.getMillis();
  
        // get event time and
        // convert it into a date
        DateFormat simple
            = new SimpleDateFormat(
                "dd MMM yyyy HH:mm:ss:SSS Z");
  
        Date result
            = new Date(millis);
  
        System.out.println(
            "Event Time "
            + simple.format(result));
    }
}


Output:

Event Time 22 Apr 1970 17:15:36:138 +0530

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

RELATED ARTICLES

Most Popular

Dominic
32352 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6720 POSTS0 COMMENTS
Nicole Veronica
11885 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6840 POSTS0 COMMENTS
Ted Musemwa
7103 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS