How would you represent date of birth in your java model?

后端 未结 6 655
孤城傲影
孤城傲影 2020-12-16 01:56

And wait, don\'t rush to answer \"java.util.Date\", consider the following scenario.

Person object having 2 fields: \"birthday\" and \"nextMeeting\" both java.util.D

6条回答
  •  攒了一身酷
    2020-12-16 02:15

    That's a very good question...

    Android for example stores birthday as String in 'yyyy-MM-dd' format. I was wondering why they don't use java.util.Date and I guess that the reason would be the same problem which you brought here.

    So I would recomment either String or some "Timezone-independent-date". But after few minutes searching in Java and joda-time documentation I have no idea how to do it.

    EDIT: Seems @Jeroen is right - use LocalDate.

提交回复
热议问题