Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java 8 Instant class does not have .plusHours?  RSS feed

 
Emiel de Munck
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Over here is some information on the Instant class https://docs.oracle.com/javase/tutorial/datetime/iso/instant.html

One of the examples given is:
Instant oneHourLater = Instant.now().plusHours(1);

However, when I try this code it does not compile. I do however see options in my IDE (Netbeans) for plusMillis, plusNanos, plusSeconds and plus, but not for plusHours.

Even when I try
java.time.Instant oneHourLater = java.time.Instant.now().plusHours(1);
to be absolutely sure of the right class used, it does not compile.

error: cannot find symbol
java.time.Instant oneHourLater = java.time.Instant.now().plusHours(1);
symbol: method plusHours(int)
location: class Instant
1 error

When I look into the code of Instant.java (once again in package java.time) I cannot find plusHours.

I must be missing something obvious here or the official Oracle tutorial is just... wrong...?
 
Tony Docherty
Bartender
Posts: 3210
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like the example is wrong.

You can do the following to add an hour:
 
Ron McLeod
Saloon Keeper
Posts: 1432
207
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:It looks like the example is wrong.

Yeah - looks like a mix-up with java.time.LocalTime where this is valid:
     LocalDateTime oneHourLater = LocalDateTime.now().plusHours(1);
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ChronoUnit? Oh yes, I can see that ChronoUnit is an enum which implements TemporalUnit for the plus() method.

Shall move to the Java8 forum.
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some of the tutorials were written before Java 8 was finished. That's the reason there are a few bugs in there.
 
Emiel de Munck
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah I see thanks for clarifying.
I think it is rather unsettling that there are still mistakes in these tutorials by Oracle, since Java 8 is already available for a while. I regarded them as the most official source and use it as exam preparation material.
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try submitting a bug. I think you need to login first though.

I've just checked the categories you should use, and here's the list:
Type: Bug
Product / Category: Java Platform Standard Edition (JDK/JRE)
Subcategory: JDK/JRE documentation, API, tutorials (doc)
 
Emiel de Munck
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:You could try submitting a bug. I think you need to login first though.

I've just checked the categories you should use, and here's the list:
Type: Bug
Product / Category: Java Platform Standard Edition (JDK/JRE)
Subcategory: JDK/JRE documentation, API, tutorials (doc)


Ah cool, thank you for the details. I just submitted it
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!