Page 1 of 1

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

Posted: Tue Jul 28, 2015 9:32 am
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

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

Posted: Tue Jul 28, 2015 10:03 am
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).

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

Posted: Thu Oct 12, 2017 12:42 pm
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?

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

Posted: Thu Oct 12, 2017 9:06 pm
by admin
No, check this article by Oracle: https://docs.oracle.com/javase/tutorial ... eriod.html
It explains the difference between Duration and Period.

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

Posted: Tue Dec 05, 2017 11:32 am
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.

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

Posted: Tue Dec 05, 2017 9:55 pm
by admin
well, what if you are working on an application that is used all over the world :)

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

Posted: Fri Dec 07, 2018 6:06 pm
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

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

Posted: Fri Dec 07, 2018 9:29 pm
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.

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

Posted: Sat Mar 13, 2021 8:06 am
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.

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

Posted: Sat Mar 13, 2021 11:00 am
by admin
Because the problem statement says, "Given that Daylight Savings Time ends on Nov 1 at 2 AM".