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.

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);
The output as below.
Date: Sat Apr 16 16:39:12 ICT 2022
Milliseconds: 1650101952053

Happy Coding 😊

Java Convert Date to String

Java Convert Date to Instant

Java Convert Date to Calendar

Java Date by Examples