I would also read the documentation. In the given example, for example, you don't know if the desired fixed format "YYYY-MM-DD" might depend on some locale setting and only works because you happen to have the correct one in that test console.
I’m pretty sure toPlainDate() returns an object not a string.
Part of my point is this: If you have to read through the docs to see if the answer can be trusted, why didn't you just read the docs to begin with instead of asking the AI?