question to save the string in the date format.

In the list of 12 elements is the format string "yyyy-MM-dd-HH", I try to save it in the same format (yyyy-MM-dd-HH), but using the date type, not the string (for transfer to the database).

The problem is that now the format is changing (as seen in the picture when outputting to the console), what could be the problem and how to keep the original format?

enter image description here

    1 answer 1

    You received the date correctly - but you will not format it again when outputting to the console. Therefore, it is displayed as in the screenshot. If you want to see more readable output, you need to format it again. Use the format method with SimpleDateFormat

    • Thank you, I thought somewhere there was a mistake) - Anton