Found 9326 Articles for Object Oriented Programming

LocalDateTime withDayOfYear() method

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

43 Views

An immutable copy of a LocalDateTime with the day of year altered as required is done using the method withDayOfYear() in the LocalDateTime class in Java. This method requires a single parameter i.e. the day of year that is to be set in the LocalDateTime and it returns the LocalDateTime with the day of year altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt1);       LocalDateTime ... Read More

LocalDateTime isEqual() method in Java

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

78 Views

It can be checked if two LocalDateTime objects are equal or not using the isEqual() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the LocalDateTime object that is to be compared. It returns true if the two LocalDateTime objects are equal and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30");       LocalDateTime ldt2 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime ldt1 is: " + ldt1);       System.out.println("The ... Read More

LocalDateTime isBefore() method in Java

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

79 Views

It can be checked if a particular LocalDateTime is before the other LocalDateTime in a timeline using the isBefore() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the LocalDateTime object that is to be compared. It returns true if the LocalDateTime object is before the other LocalDateTime object and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-15T11:37:12");       LocalDateTime ldt2 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime ldt1 is: ... Read More

LocalDateTime isAfter() method in Java

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

92 Views

It can be checked if a particular LocalDateTime is after the other LocalDateTime in a timeline using the isAfter() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the LocalDateTime object that is to be compared. It returns true if the LocalDateTime object is after the other LocalDateTime object and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-20T11:37:12");       LocalDateTime ldt2 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime ldt1 is: ... Read More

LocalDateTime withSecond() method in Java

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

26 Views

An immutable copy of a LocalDateTime with the seconds altered as required is done using the method withSecond() in the LocalDateTime class in Java. This method requires a single parameter i.e. the second that is to be set in the LocalDateTime and it returns the LocalDateTime with the second altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt1);       LocalDateTime ldt2 = ldt1.withSecond(45);       ... Read More

LocalDateTime plusYears() method in Java

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

64 Views

An immutable copy of a LocalDateTime object where some years are added to it can be obtained using the plusYears() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the number of years to be added and it returns the LocalDateTime object with the added years.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.now();       System.out.println("The current LocalDateTime is: " + ldt);       System.out.println("The LocalDateTime with 2 years added is: ... Read More

LocalDateTime toLocalDate() method in Java

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

24 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

915 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

51 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

Advertisements