Joda DateTime解析完整日期名称

时间:2015-04-10 19:29:09

标签: scala datetime jodatime

import org.joda.time._
import org.joda.time.format._

val pattern = "MMM d HH:mm:ss Z yyyy"
val input = "Apr 10 18:31:45 +0000 2015"
DateTime.parse(input, DateTimeFormat.forPattern(pattern))

任何人都可以告诉我它为什么不起作用?

我明白了:

DateTime.parse(input, DateTimeFormat.forPattern(pattern))
java.lang.IllegalArgumentException: Invalid format: "Apr 10 18:31:45 +0000 2015"
  at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:899)
  at org.joda.time.DateTime.parse(DateTime.java:160)
  ... 43 elided

1 个答案:

答案 0 :(得分:2)

val pattern = "MMM d HH:mm:ss Z yyyy"
val input = "Apr 10 18:31:45 +0000 2015"

val format = DateTimeFormat.forPattern(pattern).withLocale(Locale.ENGLISH)
format.parseDateTime(input)

我发现了nvm;)