Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

having trouble using LocalDate, error says it can't be resolved to a type

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading