How to format LocalDate object to MM/dd/yyyy and have format persist

后端 未结 5 1193
自闭症患者
自闭症患者 2020-11-27 07:37

I am reading text and storing the dates as LocalDate variables.

Is there any way for me to preserve the formatting from DateTimeFormatter so that when I call the Lo

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 08:10

    EDIT: Considering your edit, just set parsedDate equal to your formatted text string, like so:

    parsedDate = text;
    

    A LocalDate object can only ever be printed in ISO8601 format (yyyy-MM-dd). In order to print the object in some other format, you need to format it and save the LocalDate as a string like you've demonstrated in your own example

    DateTimeFormatter formatters = DateTimeFormatter.ofPattern("d/MM/uuuu");
    String text = date.format(formatters);
    

提交回复
热议问题