#Having a unknown error LocalDate.now()

1 messages · Page 1 of 1 (latest)

mild mauve
#

Hi its me again, i am having a error about LocalDate.now() in my fileManager Class. im not sure whats the problem.
ive listed the Screen shot of my error, code and the varibles in my other Activity class.
The classes are in different Directores but in same folder. idk whats the cause of it. If anyone can help that would be appreciated.

shadow wrenBOT
#

<@&987246399047479336> please have a look, thanks.

hardy lantern
#

well it seems like you have to pass a string but you pass a LocalDate

#

and like the error Message says, it can not convert a LocalDate to a string

mild mauve
#

so what should i do then?

hardy lantern
#

pass a String

mild mauve
#

ok let me try that

#

like this?

hardy lantern
#

no

mild mauve
#

oh 😭

hardy lantern
#

you can use a DateTimeFormatter and create a format and then date.format(formatter). or .toString() then you get the ISO-format

#

and cast are done like this (String). not by just writing the type in front of it

mild mauve
#

im new to java and ill try the datatimeformatter rn

hardy lantern
#
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

LocalDate date = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
String now = date.format(formatter);

System.out.println(now);
shadow wrenBOT
mild mauve
#

case "SWM-01":
LocalDateTime currentDateTime = LocalDateTime.parse("2024-12-16T21:14:31Z", DateTimeFormatter.ISO_DATE_TIME);
return new Activity(code, "Scuba Diving",
"Experience the underwater world",
currentDateTime.plusDays(7),
120, true, 6000);

#

this?

hardy lantern
#

?

#

you want a String

#

not a LocalDateTime

mild mauve
#

I need to make the time for the activity to log

#

how will string do that?

hardy lantern
#

you coded the constructor that needs a string

#

if you want a LocalDate then change the constructor

mild mauve
#

Ok let me try remove string from constructor

hardy lantern
#

no replace it with a LocalDate

mild mauve
#

i think i fixed it

#

DOes this look alright?

#

left is my constructor and right is the method

#

it is showing no errors now

hardy lantern
#

👍

mild mauve
#

thanks man