'LocalDateTime in IntelliJ IDEA Kotlin shows as unresolved reference

java.time seems to be missing entirely. The code I'm trying it in is a simple

fun main(args: Array<String>) {
    println(LocalDateTime.now())
}

Seems like I am missing something fundamental, but all I have been doing is following along in a tutorial and it just worked for the tutor.



Solution 1:[1]

The LocalDateTime class has only been introduced in Java SE 8, so you need to compile your project against JDK 8 or newer.

Make sure that:

  • You have an installed JDK 8 or newer;

  • Your project is compiled against this JDK 8+.

    (In IntelliJ IDEA, Ctrl/?+Shift+Alt+S ? Project ? Project SDK; other build systems should be set up separately)

With the JDK configured correctly, the code should run fine as-is: (demo)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1