Apparently neither java.util.Date nor java.util.Calendar i开发者_如何转开发mplement Persistable, so cannot be used in Persistable classes. What is the best alternative for persisting dates and times?
You could write your code to expect that dates and times are kept in the Unix epoch format (number of seconds since 1/1/1970). Then your problem is simply a matter of storing a long number.
storing as a long as Dan mentions is the way to go. System.currentTimeMillis() will return milliseconds since Unix Epoch, which is 1/1/1970 GMT. It's obviously fairly trivial to convert between seconds and milliseconds. For timezone corrections, the Calendar class can help you handle this.
Note:
getInstance(Timezone zone)
getTimeInMillis()
setTimeInMillis(long millis)
setTimeZone(Timezone value)
加载中,请稍侯......
精彩评论