Found 4334 Articles for Java 8

LocalDate getEra() method in Java

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

58 Views

The era for a particular LocalDate can be obtained using the getEra() method in the LocalDate class in Java. This method requires no parameters and it returns the era applicable for the LocalDate.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main { public static void main(String[] args) { LocalDate ld = LocalDate.parse("2019-02-14"); System.out.println("The LocalDate is: " + ld); System.out.println("The era is: " + ld.getEra()); } }OutputThe LocalDate is: 2019-02-14 The ... Read More

LocalDate lengthOfMonth() method in Java

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

82 Views

The length of the month in a particular LocalDate is obtained using the method lengthOfMonth() in the LocalDate class in Java. This method requires no parameters and it returns the length of the month in a particular LocalDate i.e. 28, 29, 30 or 31.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main { public static void main(String[] args) { LocalDate ld = LocalDate.parse("2019-02-15"); System.out.println("The LocalDate is: " + ld); System.out.println("The length of the ... Read More

LocalTime minusHours() method in Java

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

108 Views

An immutable copy of a LocalTime object where some hours are subtracted from it can be obtained using the minusHours() method in the LocalTime class in Java. This method requires a single parameter i.e. the number of hours to be subtracted and it returns the LocalTime object with the subtracted hours.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalTime lt = LocalTime.now(); System.out.println("The current LocalTime is: " + lt); ... Read More

LocalTime minusMinutes() method in Java

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

118 Views

An immutable copy of a LocalTime object where some minutes are subtracted from it can be obtained using the minusMinutes() method in the LocalTime class in Java. This method requires a single parameter i.e. the number of minutes to be subtracted and it returns the LocalTime object with the subtracted minutes.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalTime lt = LocalTime.now(); System.out.println("The current LocalTime is: " + lt); ... Read More

LocalTime minusNanos() method in Java

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

89 Views

An immutable copy of a LocalTime object where some nanoseconds are subtracted from it can be obtained using the minusNanos() method in the LocalTime class in Java. This method requires a single parameter i.e. the number of nanoseconds to be subtracted and it returns the LocalTime object with the subtracted nanoseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.now();       System.out.println("The current LocalTime is: " + lt);       System.out.println("The LocalTime with 1000 nanoseconds subtracted is: ... Read More

LocalDateTime format() method in Java

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

254 Views

The LocalDateTime can be formatted with the specified formatter using the format() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the LocalDateTime object to be formatted and it returns the formatted LocalDateTime with the specified formatter.A program that demonstrates this is given as follows −Example Live Demoimport java.util.*; import java.time.*; import java.time.format.DateTimeFormatter; public class Main {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T14:30:47");       System.out.println("The LocalDateTime is: " + ldt);       DateTimeFormatter dtf = DateTimeFormatter.ISO_TIME;       System.out.println("The formatted LocalDateTime is: " + ... Read More

LocalDateTime withYear() method in Java

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

98 Views

An immutable copy of a LocalDateTime with the year altered as required is done using the method withYear() in the LocalDateTime class in Java. This method requires a single parameter i.e. the year that is to be set in the LocalDateTime and it returns the LocalDateTime with the 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); ... Read More

LocalDateTime getMonthValue() method in Java

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

74 Views

The month of the year is obtained using getMonthValue() method in the LocalDateTime class in Java. This method requires no parameter and it returns the month of the year which may be in the range of 1 to 12.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); System.out.println("The month is: " + ldt.getMonthValue()); ... Read More

LocalDateTime getDayOfMonth() method in Java

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

235 Views

The day of the month for a particular LocalDateTime can be obtained using the getDayOfMonth() method in the LocalDateTime class in Java. This method requires no parameters and it returns the day of the month which can be in the range of 1 to 31.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-18T11:30:15"); System.out.println("The LocalDateTime is: " + ldt); System.out.println("The day of ... Read More

LocalDateTime getDayOfWeek() method in Java

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

114 Views

The day of the week for a particular LocalDateTime can be obtained using the getDayOfWeek() method in the LocalDateTime class in Java. This method requires no parameters and it returns the day of the week.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-18T11:30:15"); System.out.println("The LocalDateTime is: " + ldt); System.out.println("The day of the week is: " + ldt.getDayOfWeek()); } ... Read More

Advertisements