表示日历对象的最佳规范字符串?
我需要将日历对象存储为字符串,并且还能够从该字符串加载日历对象。我的字符串中需要什么才能准确地表示日历包含的所有内容?
例如,如果我使用 SimpleDateFormatter 并使用模式 yyyyMMddHHmmssSSSzz ,即年、月、日、时、分、秒、毫秒和时区,我是否能够可靠地重新创建 Calendar 对象那个字符串?
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, month, date, hour, minute, second, millisecond, and timezone, would I be able to reliably recreate the Calendar object from that String?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的模式没问题,但您可能会遇到文化和语言特异性方面的困难。我建议使用月份的数字表示形式而不是三个字母的缩写,以获得最大的灵活性并避免麻烦。您还需要考虑是否需要跟踪时区信息。如果此时间戳是作为 UTC 生成的,或者您的应用程序旨在在单个时区中运行,那么就可以了。
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.
您可以只使用 millis 来表示日期时间,并为 TZ 偏移量 + 区域设置提供额外的字段。这就足够了。
You can just use millis to represent datetime and have extra field for TZ offset + Locale. That would be enough.