• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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

 
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: 11338
177
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)
 
author & internet detective
Marshal
Posts: 38687
677
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!