Date
Date from specific time
This is an example of how to get a Date from a specific time. The class Date represents a specific instant in time, with millisecond precision. Getting a Date from a specific long time implies that you should:
- Create a new Date object, using the
Date(long date)constructor, with a long parameter. The constructor allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as “the epoch”, namely January 1, 1970, 00:00:00 GMT.
We can print the date to check its value.
Let’s take a look at the code snippet that follows:
package com.javacodegeeks.snippets.core;
import java.util.Date;
public class DateFromSpecificTime {
public static void main(String[] args) {
//date after (random) years, months, days, ...
Date date = new Date(124840L * 13L * 12L * 48L * 1000L);
System.out.println(date);
}
}
Output:
Mon Aug 16 14:12:00 EEST 1999
This was an example of how to get a Date from a specific time in Java.
