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.

Byron Kiourtzoglou

Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button