how get time java code example
Example 1: How to get current date and time in java
// get current date and timein java using Calendar.getTime() method
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
// get current date and time in java using LocalDate.now() method
import java.time.LocalDate;
public class UsingLocalDate
{
public static void main(String[] args)
{
System.out.println(LocalDate.now());
}
}
Example 3: How to get current date and time in java
// get current date and time in java using LocalDateTime.now() method
import java.time.LocalDateTime;
public class UsingLocalDateTime
{
public static void main(String[] args)
{
System.out.println(LocalDateTime.now());
}
}
Example 4: java how to get current time
import java.util.Calendar;
Date currentTime = Calendar.getInstance().getTime();