Found 4336 Articles for Java 8

LocalTime withSecond() method in Java

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

33 Views

An immutable copy of a LocalTime with the seconds altered as required is done using the method withSecond() in the LocalTime class in Java. This method requires a single parameter i.e. the second that is to be set in the LocalTime and it returns the LocalTime 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) {       LocalTime lt1 = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt1);       LocalTime lt2 = lt1.withSecond(45);       ... Read More

LocalTime withNano() method in Java

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

39 Views

An immutable copy of a LocalTime with the nanoseconds altered as required is done using the method withNano() in the LocalTime class in Java. This method requires a single parameter i.e. the nanosecond that is to be set in the LocalTime and it returns the LocalTime with the nanosecond 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) {       LocalTime lt1 = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt1);       LocalTime lt2 = lt1.withNano(5);       ... Read More

LocalTime truncatedTo() method in Java

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

51 Views

An immutable truncated LocalTime object can be obtained using the truncatedTo() method in the LocalTime in Java. This method requires a single parameter i.e. the TemporalUnit till which the LocalTime object is truncated and it returns the immutable truncated object.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt.toString());       LocalTime truncatedLocalTime = lt.truncatedTo(ChronoUnit.MINUTES);       System.out.println("The truncated LocalTime is: " + truncatedLocalTime);    } }OutputThe ... Read More

LocalTime toString() method in Java

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

505 Views

The string value of the LocalTime object can be obtained using the method toString() in the LocalTime class in Java. This method requires no parameters and it returns the string value of the LocalTime object.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.parse("23:15:30");       System.out.println("The LocalTime is: " + lt.toString());    } }OutputThe LocalTime is: 23:15:30Now let us understand the above program.The string value of the LocalTime is obtained using the method toString() and then this value ... Read More

Instant minusSeconds() method in Java

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

137 Views

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

Instant plusNanos() method in Java

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

71 Views

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

Instant plusSeconds() method in Java

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

381 Views

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

Instant plusMillis() method in Java

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

125 Views

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

Instant now() Method in Java

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

8K+ Views

The current instant from the system UTC clock can be obtained using the now() method in the Instant class in Java. This method requires no parameters and it returns the current instant from the system UTC clock.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       Instant i = Instant.now();       System.out.println("The current Instant is: " + i);    } }OutputThe current Instant is: 2019-02-12T11:49:22.455ZNow let us understand the above program.The current instant from the system UTC clock is obtained using the ... Read More

Duration getUnits() method in Java

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

62 Views

The list of different units that are supported by a duration can be obtained using the method getUnits() in the Duration class in Java. This method requires no parameters and it returns the list of different units that are supported by a duration.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(5);       System.out.println("The duration is: " + d);       System.out.println("The units are: " + d.getUnits());    } }OutputThe duration is: PT5S The units are: [Seconds, ... Read More

Advertisements