java localtime get current time code example

Example 1: how to get the time in java

// 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
   }
}

Example 2: java get current time in seconds

LocalDateTime date = LocalDateTime.now();
int seconds = date.toLocalTime().toSecondOfDay();

Example 3: java how to get current time

import java.util.Calendar;
Date currentTime = Calendar.getInstance().getTime();