• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

I need explanation about two dates questions (Java OCA 8 Programmer I Study Guide, Sybex)  RSS feed

 
Ranch Hand
Posts: 142
4
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
32. What is the output of the following code?

A. 3/7/14 11:22 AM
B. 5/10/15 11:22 AM
C. 3/7/14
D. 5/10/15
E. 11:22 AM
F. The code does not compile.
G. A runtime exception is thrown.

Prints 11:22 AM .

33. What is the output of the following code?

A. 5/9/13 11:22 AM
B. 5/10/13 11:22 AM
C. 5/9/14
D. 5/10/14
E. The code does not compile.
F. A runtime exception is thrown.

Prints  5/10/13 11:22 AM


Two methods signatures are

public String format(DateTimeFormatter formatter) // in LocalDate class method

public String format(TemporalAccessor temporal) // in DateTimeFormatter class method

format method in Local Date class internally calls DateTimeFormatter  format method .

why format method in LocalDate class prints only time ???

Could anyone clarify this doubt ??

 
Ranch Hand
Posts: 39
4
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

And the answer to your question is in this row:

Let me edit it a bit further so you can see what method we are using:
DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);

We are adding a format to our LocalDateTime that only formats the Time part, thus the result will output only time.
What do you think would happen if we used this instead?
 
Narayana Bojja
Ranch Hand
Posts: 142
4
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you So much Dóra Takács for your clear explanation.
 
Sheriff
Posts: 11604
178
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Narayana Bojja wrote:Thank you So much Dóra Takács for your clear explanation.


That's indeed a very nice and clear explanation, Dóra Have a cow!

It's time for another (free) pop quiz question. What will be the output of the following code snippet?

Hope it helps!
Kind regards,
Roel
 
Dóra Takács
Ranch Hand
Posts: 39
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeey I' got a cow \o/ Thank you Roel!

And I can barely pull myself back from answering that miniquiz
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!