Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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: 39996
807
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.
 
The moustache of a titan! The ad of a flea:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic