Get Date

With this example we are going to demonstrate how to get a Date in Java. The class Date represents a specific instant in time, with millisecond precision. In short, to get a Date object you should:

  • Create a new Date object, using the Date() constructor. The constructor allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.
  • 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 getDate {
  public static void main(String[] args) {

// Create date object kai print its value
	  Date date = new Date();
	  System.out.println("Today is " + date);


Today is Sun Jul 22 19:13:44 EEST 2012

This was an example of how to get a Date in Java.

Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.
Notify of

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

Inline Feedbacks
View all comments
Back to top button