Found 9326 Articles for Object Oriented Programming

Duration equals() method in Java

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

231 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 30-Jul-2019 22:30:25

90 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 fixed() method

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

334 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

125 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

202 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

Java 8 Clock instant() method

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

160 Views

The current instant of the clock object can be obtained using the method instant() in the Clock Class in Java. This method requires no parameters and it returns the current instant of the clock object. If the instance cannot be obtained for some reason, then the DateTimeException is thrown.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(); Instant i = c.instant(); System.out.println("The ... Read More

Java 8 Clock millis() Method

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

253 Views

The current instance of the clock in milliseconds can be obtained using the method millis() in the Clock Class in Java. This method requires no parameters and it returns the current instant of the clock in milliseconds. If the instance cannot be obtained for some reason, then the DateTimeException is thrown.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();       long ms = c.millis();       System.out.println("The clock is: " + c);     ... Read More

Java 8 Clock equals() Method

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

138 Views

The equality of two Java clock objects can be checked using the method equals() in the Clock Class in Java. This method requires a single parameter i.e. the object that is to be compared with the existing clock object. Also it returns true if both the clock objects are equal and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Clock; import java.time.ZoneId; public class Demo {    public static void main(String[] args) {       Clock c1 = Clock.systemDefaultZone();       Clock c2 = Clock.systemDefaultZone();       System.out.println("Clock c1: " + c1.toString());   ... Read More

Clock systemUTC() Method in Java

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

183 Views

The current instance of the clock with the UTC time zone can be obtained using the method systemUTC() in the Clock Class in Java. This method requires no parameters and it returns the current instance of the clock with the UTC 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.systemUTC();       Instant i = c.instant();       ZonedDateTime zdt = i.atZone(c.getZone());     System.out.println(zdt.toString()); } }Output2019-02-07T08:00:46.924ZNow let us understand the ... Read More

Clock systemDefaultZone() Method in Java

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

78 Views

The current instance of the clock with the default time zone can be obtained using the method systemDefaultZone() in the Clock Class in Java. This method requires no parameters and it returns the current instance of the clock with the default 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(); Instant i = c.instant(); ZonedDateTime zdt = i.atZone(c.getZone()); ... Read More

Advertisements