开发者

Android - problem parsing date

开发者 https://www.devze.com 2023-03-13 17:37 出处:网络
I am using the following piece of code to parse a date - DateFormat dateFormatIn = new SimpleDateFormat(\"yyyy-MM-dd\'T\'HH:mm:ss.S\'Z\'\");

I am using the following piece of code to parse a date -

DateFormat dateFormatIn = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
Strin开发者_如何转开发g ts = "2011-06-15T17:34:09.291Z";
String timestamp = dateFormatIn.format(ts);

It throws me an IllegalArgumentException. Any idea what is the right way to go about it?


DateFormat.format() expects a Date as parameter and not a String.

http://developer.android.com/reference/java/text/DateFormat.html#format(java.util.Date)

U need to use DateFormat.parse() to get the Date

0

精彩评论

暂无评论...
验证码 换一张
取 消