Found 9150 Articles for Object Oriented Programming

Duration get() method in Java

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

501 Views

The value of the chronological unit can be obtained using the method get() in the Duration class in Java. This method requires a single parameter i.e. the TemporalUnit for which the value is required. Also, the value of the chronological unit is returned by this method.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.ofMinutes(2);       System.out.println("The duration in minutes is: " + d);       long seconds = d.get(ChronoUnit.SECONDS);     System.out.println("The ... Read More

Duration ofSeconds() method in Java

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

1K+ Views

The duration can be obtained in a one second format using the ofSeconds() method in the Duration class in Java. This method requires two parameters i.e. the number of seconds and the adjustment required in nanoseconds. Also, it returns the duration in a one second format. If the capacity of the duration is exceeded, then the ArithmeticException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       long seconds = 515793;     long adjustment = 100; ... Read More

Duration negated() method in Java

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

160 Views

An immutable copy of a duration where the duration is negated can be obtained using the negated() method in the Duration class in Java. This method requires no parameters and it returns the negated duration. Also, if a numeric overflow occurs the ArithmeticException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class GFG { public static void main(String[] args) { Duration d = Duration.ofHours(1); System.out.println("The duration is: " + d); System.out.println("A copy with ... Read More

Duration toMinutes() method in Java

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

230 Views

The value of a duration in the form of a number of minutes can be obtained using the method toMinutes() in the Duration class in Java. This method does not require any parameters and it returns the duration in the form of a number of minutes.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class GFG { public static void main(String[] args) { Duration d = Duration.ofDays(1); System.out.println("The duration is: " + d); System.out.println("Number of ... Read More

Duration toHours() method in Java

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

200 Views

The value of a duration in the form of a number of hours can be obtained using the method toHours() in the Duration class in Java. This method does not require any parameters and it returns the duration in the form of a number of hours.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class GFG { public static void main(String[] args) { Duration d = Duration.ofDays(1); System.out.println("The duration is: " + d); System.out.println("Number of ... Read More

Duration equals() method in Java

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

361 Views

The equality of two durations can be determined using the equals() method in the Duration class in Java. This method requires a single parameter i.e. the duration to be compared. Also, it returns true if both the durations are equal and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class GFG { public static void main(String[] args) { Duration d1 = Duration.ofDays(1); Duration d2 = Duration.ofHours(24); boolean flag = d1.equals(d2); ... Read More

Java 8 clock offset() method

Samual Sam
Updated on 07-Nov-2024 17:48:09

181 Views

In this article, we will learn how to use the Clock.fixed() method in Java to obtain a fixed instant on the clock. This method, part of the java.time package is primarily used for testing purposes. It requires two parameters: a fixed Instant and a ZoneId (time zone). The Clock.fixed() method returns a clock that always returns the fixed instant, ensuring the clock’s time remains constant.  Problem StatementGiven the need to use the Clock.fixed() method to get a fixed instant in a specific time zone and display the fixed clock, we will write a program that achieves this task.Input Instant: ... Read More

Java 8 Clock fixed() method

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

432 Views

The fixed instant on the clock can be obtained using the method fixed() in the Clock Class in Java. This method requires two parameters i.e. the fixed instant and the time zone. Also, it returns the fixed instant on the clock. The fixed() method is normally used for testing purposes.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(); ZoneId zId = ZoneId.of("Australia/Melbourne"); ... Read More

Java 8 Clock getZone() method

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

181 Views

The time zone required for the date and time creation can be obtained using the method getZone() in the Clock Class in Java. This method requires no parameters and it returns the required time zone.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       Clock c = Clock.systemDefaultZone();     ZoneId z = c.getZone(); System.out.println("The clock is: " + c); System.out.println("The ZoneId is: " + z); } ... Read More

Java 8 Clock hashCode() method

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

270 Views

The hash code for a clock object can be obtained using the method hashCode() in the Clock Class in Java. This method requires no parameters and it returns the acceptable hash code for a clock object.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { Clock c = Clock.systemDefaultZone(); int hashCode = c.hashCode(); System.out.println("The clock is: " + c); System.out.println("The hash ... Read More

Advertisements