• Post Reply Bookmark Topic Watch Topic
  • New Topic

unable to print time with SHORT and MEDIUM

 
Manish Bilung
Greenhorn
Posts: 13
Chrome Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

Please have a look at the below code:



I am unable to print time in output. Kindly help.
 
Stephan van Hulst
Bartender
Posts: 6654
90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should probably check out the Predefined Formatters table in the DateTimeFormatter class documentation.
 
Manish Bilung
Greenhorn
Posts: 13
Chrome Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:You should probably check out the Predefined Formatters table in the DateTimeFormatter class documentation.


sorry Stephan, failed to mention that I was referring to the expected output in the book OCA Study Guide by Jeanne Boyarsky and Scott Selikoff.

Page number 149.

Regards,
Manish
 
Stephan van Hulst
Bartender
Posts: 6654
90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have the book. What is the expected result shown there?
 
Emanuel Frua
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manish, the problem is in the method. You need a ofLocalizedDateTime() or ofLocalizedTime().
The FormatStyle is trying to deceive you. Run the same date with a SHORT and MEDIUM to look the difference.
 
Manish Bilung
Greenhorn
Posts: 13
Chrome Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:I don't have the book. What is the expected result shown there?

Hello Stephen,

This is an excerpt from the book:



ISO is a standard for dates. The output of the previous code looks like this:

2020-01-20
11:12:34
2020-01-20T11:12:34 [sic]

Regards,
Manish
 
Manish Bilung
Greenhorn
Posts: 13
Chrome Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:I don't have the book. What is the expected result shown there?


Hello Stephen, Please ignore the previous reply.

This is an excerpt from the book:



I replicated the same code but was unable to print short time.

Regards,
Manish
 
Manish Bilung
Greenhorn
Posts: 13
Chrome Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emanuel Frua wrote:Hi Manish, the problem is in the method. You need a ofLocalizedDateTime() or ofLocalizedTime().
The FormatStyle is trying to deceive you. Run the same date with a SHORT and MEDIUM to look the difference.


Thanks Emanuel for the reply. I don't have access to my workstation at the moment.

Will try your suggestion and will revert back.

Regards,
Manish
 
Stephan van Hulst
Bartender
Posts: 6654
90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because your code is different from the code in the book.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!