Found 7442 Articles for Java

Duration toMillis() method in Java

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

172 Views

The value of a particular duration in the number of milliseconds can be obtained using the toMillis() method in the Duration class in Java. This method requires no parameters and it returns the duration in the number of milliseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofSeconds(1);       System.out.println("The duration is: " + d);       System.out.println("The number of milliseconds in the duration is: " + d.toMillis());    } }OutputThe duration is: PT1S The number of ... Read More

Duration minusDays() method in Java

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

130 Views

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

Duration minusHours() method in Java

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

86 Views

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

Duration plusHours() method in Java

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

104 Views

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

Duration plusMinutes() method in Java

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

136 Views

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

Duration plusSeconds() method in Java

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

124 Views

An immutable copy of a duration where some seconds are added to it can be obtained using the plusSeconds() method in the Duration class in Java. This method requires a single parameter i.e. the number of seconds to be added and it returns the duration with the added seconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofSeconds(12);       System.out.println("The duration is: " + d);       System.out.println("A copy with 5 seconds added to the duration is: ... Read More

Duration plusMillis() method in Java

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

81 Views

An immutable copy of a duration where some milliseconds are added to it can be obtained using the plusMillis() method in the Duration class in Java. This method requires a single parameter i.e. the number of milliseconds to be added and it returns the duration with the added milliseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofSeconds(1);       System.out.println("The duration is: " + d);       System.out.println("A copy with 1000 milliseconds added to the duration is: ... Read More

Duration toDays() method in Java

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

124 Views

The value of a particular duration in the number of days can be obtained using the toDays() method in Java. This method requires no parameters and it returns the duration in the number of days.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofHours(48);       System.out.println("The duration is: " + d);       System.out.println("The number of days in the duration is: " + d.toDays());    } }OutputThe duration is: PT48H The number of days in the duration ... Read More

Duration multipliedBy() method in Java

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

99 Views

An immutable copy of a duration where the required duration is multiplied by a value can be obtained using the method multipliedBy() in the Duration class in Java. This method requires a single parameter i.e. the value which is to be multiplied and it returns the immutable copy of the duration which is multiplied by a value.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofHours(7);       System.out.println("The duration is: " + d);       ... Read More

Duration dividedBy() method in Java

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

97 Views

An immutable copy of a duration where the required duration is divided by a value can be obtained using the method dividedBy() in the Duration class in Java. This method requires a single parameter i.e. the value which is to be divided and it returns the immutable copy of the duration which is divided by a value.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofHours(15);       System.out.println("The duration is: " + d);       ... Read More

Advertisements