本文介绍了使用SimpleDateFormat时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用SimpleDateFormat类从该字符串中解析出DateTime:
I'm trying to use the SimpleDateFormat class to parse a DateTime out of this string:
2012年7月5日11:38:02,442 UTC AM
05-Jul-2012 11:38:02,442 UTC AM
我尝试了以下格式字符串:
I tried the following format string:
SimpleDateFormat dateformatYYYYMMDD = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss,SSS z a");
Date temp = dateformatYYYYMMDD.parse(time);
但是会产生错误:
错误:无法解析的日期:"
Error: Unparseable date: ""
如果我使用zZ,则会得到:错误:无法解析的日期:"2012年7月5日11:38:02,442 UTC AM"
If I use zZ I get : Error: Unparseable date: "05-Jul-2012 11:38:02,442 UTC AM"
关于如何解决此问题的任何提示?
Any hints on how to get around this?
推荐答案
当我尝试运行时,对我来说效果很好:
That works fine for me when I try to run:
String time = "05-Jul-2012 11:38:02,442 UTC AM";
SimpleDateFormat dateformatYYYYMMDD = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss,SSS z a");
Date temp = dateformatYYYYMMDD.parse(time);
您确定time
设置为某项内容吗?
Are you sure time
is set to something?
这篇关于使用SimpleDateFormat时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!