I’m a beginner programmer and I have just started learning about topics related to date and time. The code that my teacher writes works just fine on his computer, but in mine I can’t even run it.
This is the code in question:
package application;
import java.time.LocalDate;
import java.time.LocalDateTime;
public class Program {
public static void main(String[] args){
LocalDate d01 = new LocalDate.now();
LocalDateTime d02 = new LocalDateTime.now();
System.out.println(d01);
System.out.println(d02);
}
}
Both LocalDate.now(); and LocalDateTime.now(); are marked as errors, and it says on the console:
LocalDate.now cannot be resolved to a type
LocalDateTime.now cannot be resolved to a type
I searched for this error on the internet and found only one person that had it, and he just changed the version of his IDE to fix it. Meanwhile on my pc I tried running it on VSCode, NetBeans and Eclipse, and the same problem kept happening on all of these. I also tried updating my java, but it didn’t really matter because I already had a previous version of java 17 installed. This is my first time asking here so I apologize if something is out of place.
>Solution :
new LocalDateTime.now() is the incorrect syntax, and should just be LocalDate.now() without the new.