我有一个String as
strikedate="2011-11-19T00:00:00.000-05:00"
Run Code Online (Sandbox Code Playgroud)
我需要将它放入java.util.Date中.有人请告诉我如何将此String转换为Date
Jon*_*eet 15
当然 - 使用SimpleDateFormat.
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
Date parsed = sdf.parse(text);
Run Code Online (Sandbox Code Playgroud)
编辑:Eek - 由于你的时区格式,它并不那么简单.以上将没有冒号.您可能需要使用Joda Time来使用冒号解析版本.现在检查......
编辑:是的,有了Joda Time你可以使用:
DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
DateTime parsed = formatter.parseDateTime(text);
// If you really need it
Date date = parsed.toDate();
Run Code Online (Sandbox Code Playgroud)
Joda Time也是一个更好的日期/时间API - 如果可以的话,我强烈建议您使用它.