Answers for "get current time only in java"

4

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);
   }
}
Posted by: Guest on November-30-2020
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
   }
}
Posted by: Guest on June-01-2021
0

java get current time in seconds

LocalDateTime date = LocalDateTime.now();
int seconds = date.toLocalTime().toSecondOfDay();
Posted by: Guest on September-02-2020
2

java how to get current time

import java.util.Calendar;
Date currentTime = Calendar.getInstance().getTime();
Posted by: Guest on November-08-2020
2

How to get current date and time in java

// how to get current date and time in java 
// using Date class and System.currentTimeMillis() method
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); 
   }
}
Posted by: Guest on November-30-2020

Code answers related to "get current time only in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language