Found 4332 Articles for Java 8

LocalDateTime toLocalDate() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

26 Views

The representation of the LocalDate can be obtained using the method toLocalDate() in the LocalDateTime class in Java. This method requires no parameters and it returns the LocalDate value of the LocalDateTime object.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.util.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The LocalDate representation is: " + ldt.toLocalDate());    } }OutputThe LocalDateTime is: 2019-02-18T23:15:30 The LocalDate representation is: 2019-02-18Now let us understand the above program.First ... Read More

LocalDateTime toLocalTime() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

37 Views

The representation of the LocalTime can be obtained using the method toLocalTime() in the LocalDateTime class in Java. This method requires no parameters and it returns the LocalTime value of the LocalDateTime object.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.util.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The LocalTime representation is: " + ldt.toLocalTime());    } }OutputThe LocalDateTime is: 2019-02-18T23:15:30 The LocalTime representation is: 23:15:30Now let us understand the above program.First ... Read More

LocalDateTime toString() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

973 Views

The string value of the LocalDateTime object can be obtained using the method toString() in the LocalDateTime class in Java. This method requires no parameters and it returns the string value of the LocalDateTime object.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt.toString());    } }OutputThe LocalDateTime is: 2019-02-18T23:15:30Now let us understand the above program.The string value of the LocalDateTime is obtained using the method toString() and then this value ... Read More

LocalDateTime isSupported() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

57 Views

It can be checked if a ChronoUnit is supported by the LocalDateTime class or not by using the isSupported() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the ChronoUnit to check. It returns true if the ChronoUnit is supported by the LocalDateTime class and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.now();       System.out.println("The LocalDateTime is: " + ldt);       boolean flag = ldt.isSupported(ChronoUnit.HOURS);   ... Read More

LocalDateTime plus() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

156 Views

An immutable copy of a LocalDateTime where the required duration is added to it can be obtained using the plus() method in the LocalDateTime class in Java. This method requires two parameters i.e. the duration to be added and the TemporalUnit of the duration. Also, it returns the LocalDateTime object with the required duration added to it.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.now();       System.out.println("The LocalDateTime is: " + ldt);       ... Read More

LocalDateTime minus() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

2K+ Views

An immutable copy of a LocalDateTime where the required duration is subtracted from it can be obtained using the minus() method in the LocalDateTime class in Java. This method requires two parameters i.e. the duration to be subtracted and the TemporalUnit of the duration. Also, it returns the LocalDateTime object with the required duration subtracted from it.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.now();       System.out.println("The LocalDateTime is: " + ldt);       ... Read More

LocalDateTime parse() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

162 Views

The LocalDateTime instance can be obtained from a string value using the parse() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the string which is to be parsed. This string cannot be null. Also, it returns the LocalDateTime instance obtained from the string value that was passed as a parameter.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt);    } }OutputThe LocalDateTime is: 2019-02-18T23:15:30Now ... Read More

LocalDateTime query() Method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

88 Views

The LocalDateTime object can be queried as required using the query method in the LocalDateTime class in Java. This method requires a single parameter i.e. the query to be invoked and it returns the result of the query.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt);       String precision = ldt.query(TemporalQueries.precision()).toString();       System.out.println("The Precision for the LocalDateTime is: "+ precision);    } }OutputThe LocalDateTime ... Read More

LocalDateTime now() Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

2K+ Views

The current date-time can be obtained from the system clock in the default time zone using the now() method in the LocalDateTime class in Java. This method requires no parameters and it returns the current date-time from the system clock in the default time zoneA program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.now();       System.out.println("The LocalDateTime is: " + ldt);    } }OutputThe LocalDateTime is: 2019-02-18T06:04:31.369Now let us understand the above program.The current date-time is obtained from ... Read More

LocalDateTime until() Method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

4K+ Views

The difference between two LocalDateTime objects can be obtained using the until() method in the LocalDateTime class in Java. This method requires two parameters i.e. the end date for the LocalDateTime object and the Temporal unit. Also, it returns the difference between two LocalDateTime objects in the Temporal unit specified.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30");       LocalDateTime ldt2 = LocalDateTime.parse("2019-02-19T12:21:30");       System.out.println("The first LocalDateTime is: " + ldt1);     ... Read More

Advertisements