Best canonical String to represent a Calendar object?
I need to store a Calendar object as a String and also be able to load a Calendar object from that String. What do I need in my String to accurately represent everything a Calendar holds?
For instance, if I used SimpleDateFormatter and use the pattern yyyyMMddHHmmssSSSzz
, which is year, 开发者_C百科month, date, hour, minute, second, millisecond, and timezone, would I be able to reliably recreate the Calendar object from that String?
Your pattern is OK but you may encounter difficulty with culture and language specificity. I would recommend using the numerical representation of the month instead of the three-letter abbreviation for the most flexibility and to avoid trouble. You also need to consider whether or not you need to track timezone info. If this time stamp was generated as UTC or your app is meant to run in a single timezone then you're fine.
You can just use millis to represent datetime and have extra field for TZ offset + Locale. That would be enough.
精彩评论