[HD Pg 344, Sec. 12.3.2 - creating-a-date-time-object-using-the-static-parse-methods]

Moderator: admin

Post Reply
OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

[HD Pg 344, Sec. 12.3.2 - creating-a-date-time-object-using-the-static-parse-methods]

Post by OCAJO1 » Fri Apr 19, 2019 6:42 pm

Code: Select all

        Period ppw = Period.parse("p2w");
        Period ppW = Period.parse("P10W");
        Period ppy = Period.parse("p10y2m6w12d");
        System.out.println("\n"+ppw+" "+ppW+" "+ppy);
In the above test all the weeks were automatically converted to days when printed. So has something changed in JVM, or the phrase in the book is not referring to the results?

Last line of the first paragraph under "Parsing a string to create a Period" heading.
p1Y2w means 1 year and 2 weeks.

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

Re: [HD Pg 344, Sec. 12.3.2 - creating-a-date-time-object-using-the-static-parse-methods]

Post by admin » Fri Apr 19, 2019 8:24 pm

You mean, "For example, P1Y10M3d means 1 year, 10 months, and 3 days, P1Y3D means 1 year and 3 days. p1Y2w means 1 year and 2 weeks"? It is correct. It is talking about what these specification strings imply. i.e. y is for years, d is for days, m is for months, and w is for weeks.

It is not talking about how the Period object gets printed. Should be made clear.
If you like our products and services, please help us by posting your review here.

OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

Re: [HD Pg 344, Sec. 12.3.2 - creating-a-date-time-object-using-the-static-parse-methods]

Post by OCAJO1 » Sat Apr 20, 2019 1:48 pm

Ok. By the way, is there some reason that weeks get converted to days when printed? What if the print results had to show the weeks?

Thanks

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

Re: [HD Pg 344, Sec. 12.3.2 - creating-a-date-time-object-using-the-static-parse-methods]

Post by admin » Sat Apr 20, 2019 9:37 pm

The Javadoc says, "The supported units of a period are YEARS, MONTHS and DAYS." Only the API designers can answer why they decided not to support WEEKS as well. I don't remember coming across any reason for this.

If you want to print weeks, you need to get days and divide by 7. There is no getWeeks method in Period.
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 77
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 344, Sec. 12.3.2 - creating-a-date-time-object-using-the-static-parse-methods]

Post by Username987654 » Wed May 22, 2019 3:37 pm

LocalDate uses ISO_DATE, LocalTime uses ISO_TIME
should be
LocalDate uses ISO_LOCAL_DATE, LocalTime uses ISO_LOCAL_TIME
?

(I accidentally discovered this while looking at the Example column for Predefined Formatters at https://docs.oracle.com/javase/8/docs/a ... atter.html)

Apparently, there may be differences? Does the exam expect us to know these differences?
Example:
ISO_LOCAL_DATE ISO Local Date '2011-12-03'
ISO_DATE ISO Date with or without offset '2011-12-03+01:00'; '2011-12-03')

Reference:
https://docs.oracle.com/javase/8/docs/a ... rSequence- https://docs.oracle.com/javase/8/docs/a ... rSequence-

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

Re: [HD Pg 344, Sec. 12.3.2 - creating-a-date-time-object-using-the-static-parse-methods]

Post by admin » Wed May 22, 2019 10:22 pm

You are right. It should be the "LOCAL" versions. Added to errata.
No, you are not expected to know about these differences in the exam.
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 77
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 344, Sec. 12.3.2 - creating-a-date-time-object-using-the-static-parse-methods]

Post by Username987654 » Wed May 22, 2019 10:27 pm

Great to hear. One more thing, I was puzzled by this, but I think that possibly
Just like the no-args parse method, the toString method uses the ISO format for generating
the string.
should be
Just like the non-DateTimeFormatter arg parse method, the toString method uses the ISO format for generating
the string.
?

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

Re: [HD Pg 344, Sec. 12.3.2 - creating-a-date-time-object-using-the-static-parse-methods]

Post by admin » Wed May 22, 2019 11:33 pm

Correct!
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], Google [Bot] and 6 guests