Home » Core Java » util » Date » Get Date

About Ilias Tsagklis

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

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);
	 
  }
}

Output:

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

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

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments