// get current time in java using LocalTime.now() method
import java.time.LocalTime;
public class UsingLocalDate
{
public static void main(String[] args)
{
System.out.println(LocalTime.now());
// hr : min : sec.fimto sec
}
}
import java.util.Calendar;
Date currentTime = Calendar.getInstance().getTime();
LocalDateTime date = LocalDateTime.now();
int seconds = date.toLocalTime().toSecondOfDay();
System.out.println(LocalTime.now());
import java.util.Calendar;
import java.util.Date;
import java.time.ZonedDateTime;
public class Example {
public static void main(String[] args)
{
//Getting the current date
Date date = new Date();
//This method returns the time in millis
long timeMilli = date.getTime();
System.out.println("Time in milliseconds using Date class: " + timeMilli);
//creating Calendar instance
Calendar calendar = Calendar.getInstance();
//Returns current time in millis
long timeMilli2 = calendar.getTimeInMillis();
System.out.println("Time in milliseconds using Calendar: " + timeMilli2);
//Java 8 - toEpochMilli() method of ZonedDateTime
System.out.println("Getting time in milliseconds in Java 8: " +
ZonedDateTime.now().toInstant().toEpochMilli());
}
}