Java Convert Date to Milliseconds
Tags: Java Date
In this Java core tutorial we learn how to convert a java.util.Date object into milliseconds value in Java programming language.
How to convert Date to milliseconds in Java
In Java we can use the Date.getTime() method to get the number of milliseconds since January 1, 1970, 00:00:00 GMT from a given Date object as following example Java code.
ConvertDateToMillisecondsExample1.java
import java.util.Date;
public class ConvertDateToMillisecondsExample1 {
public static void main(String... args) {
Date date = new Date();
// Convert Date to milliseconds
long milliseconds = date.getTime();
System.out.println("Date: " + date);
System.out.println("Milliseconds: " + milliseconds);
}
}
Date: Sat Apr 16 16:39:12 ICT 2022
Milliseconds: 1650101952053
Happy Coding 😊