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

后端 未结 6 692
孤城傲影
孤城傲影 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:32

    Somehow, the two java systems will have to agree on Calendar/TimeZone information, or the Date object will need to be converted to a timestamp when being passed to the remote system.

    The simplest method might be to simply require all clients to treat the birthday as a GMT time --- when they display/compare/whatever the birthdays, have them create a Calendar with the "GMT" TimeZone, and then setTime() on it with the supplied Date.

    If you're working with the model locally at all, you should really have a Date object, not just a timestamp.

提交回复
热议问题