• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

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

 
Greenhorn
Posts: 18
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41763
887
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Squanch that. And squanch this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic