Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting LocalDateTime to a long (Java OCA 8 Programmer I Study Guide)

 
Cedric Georges
Greenhorn
Posts: 18
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 146, in section "Converting to a long", the text is indicating that LocalDateTime has a toEpochTime() function that can be used to convert a LocalDateTime into a long.

I have tried this function:

But NetBeans gives me the following result:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code -
Erroneous sym type: java.time.LocalDateTime.toEpochTime at ...


On http://docs.oracle.com/javase/8/docs/api/, I don't find anything about toEpochTime. But there is a toEpochSecond function.

Can you help me please?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cedric Georges wrote:But NetBeans gives me the following result:

NetBeans? You should use your favourite text editor and javac/java

Cedric Georges wrote:On http://docs.oracle.com/javase/8/docs/api/, I don't find anything about toEpochTime. But there is a toEpochSecond function.

Can you help me please?

Probably nothing more but a (minor) typo in the study guide. The Java API of LocalDateTime clearly mentions the toEpochSecond method (and just like the Java compiler, the Java API is always correct ). But in order to invoke this method, you'll need a zone offset as well (and null is not allowed). And for completeness: there's a LocalDateTime.ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset) as well. So it definitely is xxEpochSecond (and not xxEpochTime).

(PS. I notified the authors of this errata item)
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. I didn't reply to this one right away because I wanted to get to a computer and see how I didn't catch it when running the example. And I see why. It is a sidebar of an API method and not something I tried to run. Oops.

Thanks for reporting. Added to the errata. Have a cow for being the third person to report an error that isn't a simple typo.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic