• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
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?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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)
 
author & internet detective
Posts: 40212
816
Eclipse IDE VI Editor Java
  • 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.
 
Have you no shame? Have you no decency? Have you no tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic