使用time.parse()时是否有TimeFormatException?

时间:2011-03-21 06:23:42

标签: android exception time

我正在尝试持久存储时间数据。我将时间写入首选项作为字符串传递time.toString(),然后使用time.parse(String)方法从字符串中恢复它。但是,我发现parse方法抛出了一个TimeFormatException,特别是:

android.util.TimeFormatException: Unexpected character 0x41 at pos=15. Expected Z

我使用logcat查看我传递给解析的字符串,看起来很正常:

20110321T021030America/Detroit(1,79,-14400,1,1300687830)

任何人都可以弄清楚为什么会这样吗? “预期的Z”是指具体是字母Z,还是指任何整数,或者是什么?为什么会发生这种情况?似乎解析Time的toString()将是确保没有timeformatexception的最简单方法,但我仍然得到一个。

2 个答案:

答案 0 :(得分:1)

它可能只是无法识别格式。您可以使用time.getTime()来获取unix时间值,这可能更容易使用。

答案 1 :(得分:0)

解析已传递给time.parse()的日期格式的问题;功能 请参阅链接以纠正您的问题 Custom Date and Time Format Strings