About Question enthuware.ocajp.i.v8.2.1484 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
islam.amin099
Posts: 4
Joined: Mon Jul 20, 2015 1:47 pm
Contact:

About Question enthuware.ocajp.i.v8.2.1484 :

Post by islam.amin099 »

Hi everyone,
Do you have any recommendations for a book that has well coverage for the new Date and Time API?
Thanks in advance.
Regards,
Islam Amin

admin
Site Admin
Posts: 10113
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1484 :

Post by admin »

Oracle's Date and Time API summary is the best for exam purpose: https://docs.oracle.com/javase/8/docs/a ... mmary.html
Also, go through the descriptions of the important classes (Listed on the page mentioned above).
If you like our products and services, please help us by posting your review here.

JuergGogo
Posts: 28
Joined: Mon Sep 25, 2017 8:16 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1484 :

Post by JuergGogo »

Code: Select all

import java.time.*;
public class TestClass {
    public static void main(String[] args) { 
        
        LocalDateTime ld = LocalDateTime.of(2017, Month.OCTOBER, 28, 10, 0); 
        ZonedDateTime date = ZonedDateTime.of(ld, ZoneId.of("Europe/Paris")); 
        date = date.plus(Duration.ofDays(1)); 
        
        System.out.println(ld);       // 2017-10-28T10:00
        System.out.println(date);   // 2017-10-29T09:00+01:00[Europe/Paris]
        
        date = ZonedDateTime.of(ld, ZoneId.of("Europe/Paris")); 
        date = date.plus(Period.ofDays(1));
        
        System.out.println(ld);      // 2017-10-28T10:00
        System.out.println(date);  // 2017-10-29T10:00+01:00[Europe/Paris]      
    } 
}
Durations and periods differ in their treatment of daylight savings time when added to ZonedDateTime. A Duration will add an exact number of seconds, thus a duration of one day is always exactly 24 hours. By contrast, a Period will add a conceptual day, trying to maintain the local time.
It's the opposite, no? Duration adapts time to DST and Period is fix 24h?

admin
Site Admin
Posts: 10113
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1484 :

Post by admin »

No, check this article by Oracle: https://docs.oracle.com/javase/tutorial ... eriod.html
It explains the difference between Duration and Period.
If you like our products and services, please help us by posting your review here.

belforweb@gmail.com
Posts: 1
Joined: Tue Nov 07, 2017 8:10 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1484 :

Post by belforweb@gmail.com »

Here is a bug in test.
I live not in US, so I do not need to know then US people changes time to winter.
It is stupid.
No body cears about US time in my country.

admin
Site Admin
Posts: 10113
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1484 :

Post by admin »

well, what if you are working on an application that is used all over the world :)
If you like our products and services, please help us by posting your review here.

oumayma
Posts: 3
Joined: Sat Oct 20, 2018 7:14 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1484 :

Post by oumayma »

Hi,
please why this is the correct one?

2015-11-01T09:00-05:00[US/Eastern]
2015-11-01T10:00-05:00[US/Eastern]

I have chosen this one :

2015-11-01T10:00-05:00[US/Eastern]
2015-11-01T10:00-05:00[US/Eastern]

Duration.ofDays(1) is 24h
Period.ofDays(1) is 1 day

For me, they are the same? what I'm missing here? thanks

admin
Site Admin
Posts: 10113
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1484 :

Post by admin »

Period of 24h and Duration of 1D are not same. Check this article by Oracle: https://docs.oracle.com/javase/tutorial ... eriod.html
It explains the difference between Duration and Period.
If you like our products and services, please help us by posting your review here.

burlacu.valeri
Posts: 8
Joined: Tue Jan 26, 2021 7:55 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1484 :

Post by burlacu.valeri »

Hi, I understand what the Period add 24h and Duration 1 Day. But why the hour is changed from 10:00 to 9:00?

2015-11-01T09:00-05:00[US/Eastern]

Year DST Start (Clock Forward) DST End (Clock Backward)
2015 Sunday, 29 March, 02:00 Sunday, 25 October, 03:00

Thanks.

admin
Site Admin
Posts: 10113
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1484 :

Post by admin »

Because the problem statement says, "Given that Daylight Savings Time ends on Nov 1 at 2 AM".
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 25 guests