Get Current Date using Java

In this tutorial, I am attaching simple about, How to Get Current Date using Java. The example has been tested and output is shared in the post.

CurrentDateExample1.java

package com.dineshkrish.date;
import java.util.Date;
public class CurrentDateExample1 {
public static void main(String[] args) {
// Defining Date Object
Date date = new Date();
System.out.println(date);
}
}

CurrentDateExample2.java

package com.dineshkrish.date;
import java.util.Calendar;
import java.util.Date;
public class CurrentDateExample2 {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();	
Date date = calendar.getTime();
System.out.println(date);
}
}

CurrentDateExample3.java

package com.dineshkrish.date;
import java.util.Date;
public class CurrentDateExample3 {
public static void main(String[] args) {
long millSecond = System.currentTimeMillis();
Date date = new Date(millSecond);
System.out.println(date);
}
}

Output

——————

Sat Nov 19 17:58:52 IST 2016

References

1. Java API Documentaion

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *