syntax for current date in java code example
Example 1: How to get current date and time in java
import java.util.Calendar;
import java.util.Date;
public class UsingCalendarClass
{
public static void main(String[] args)
{
Date date = Calendar.getInstance().getTime();
System.out.println(date);
}
}
Example 2: How to get current date and time in java
import java.util.Date;
public class UsingDateClass
{
public static void main(String[] args)
{
Date dt = new Date();
System.out.println(dt);
long milliSeconds = System.currentTimeMillis();
Date date = new Date(milliSeconds);
System.out.println(date);
}
}