Get current date and time in java 8
// Get current date and time in java 8
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
public class CurrentDateTimeJava8
{
public static void main(String[] args)
{
LocalDate ld = LocalDate.now();
System.out.println("Current date: " + ld);
// get current time value
LocalTime lt = LocalTime.now();
System.out.println("Current time: " + lt);
// get current date-time value
LocalDateTime ldt = LocalDateTime.now();
System.out.println("Current date-time: " + ldt);
}
}
4.33
3
LocalDate localDate = LocalDate.now();
Thank you!
3
0
4.5
4
// 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);
}
}
Thank you!
4
0
Are there any code examples left?
New code examples in category Java