package org.kodejava.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class MillisecondsToDate {
public static void main(String[] args) {
// Create a DateFormatter object for displaying date information.
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
// Get date and time information in milliseconds
long now = System.currentTimeMillis();
// Create a calendar object that will convert the date and time value
// in milliseconds to date. We use the setTimeInMillis() method of the
// Calendar object.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(now);
System.out.println(now + " = " + formatter.format(calendar.getTime()));
}
}
The output of the code snippet above is:
1632868662762 = 29/09/2021 06:37:42.762
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024