Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LocalDateTime has not any method toEpochTime() (Java OCA 8 Programmer I Study Guide)

 
Poyan Gerami
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in chapter 3 page 146

LocalDateTime has toEpochTime() , can't find this method at all, the way i found to get the seconds is like this:

LocalDateTime time = LocalDateTime.now();
ZoneId zoneId = ZoneId.systemDefault();
long epoch = time.atZone(zoneId).toEpochSecond();


Is it any way to get it in miliseconds, same value as the old way new java.util.Date().getTime() ??
 
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
Poyan Gerami wrote:in chapter 3 page 146

LocalDateTime has toEpochTime() , can't find this method at all, the way i found to get the seconds is like this:

Have a look at the errata overview of the OCA 8 study guide and be amazed

Hope it helps!
Kind regards,
Roel
 
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
Poyan Gerami wrote:Is it any way to get it in miliseconds, same value as the old way new java.util.Date().getTime() ??

Yes, you can!Another alternative

Hope it helps!
Kind regards,
Roel

 
Poyan Gerami
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, butt still I think System.currentTimeMillis() is an easier way to get epoch time.
 
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
Poyan Gerami wrote:thanks, butt still I think System.currentTimeMillis() is an easier way to get epoch time.

Indeed! But then you are not using the new Java 8 Date/Time API
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic