def toSec(time: String): Long = {
DateTimeFormat.forPattern( """yyyy/MM/dd HH:mm:ss"""").withZone(DateTimeZone.forID("Asia/Hong_Kong")).parseDateTime(time).getMillis
}
16/01/05 14:16:26 ERROR Executor: Exception in task 0.0 in stage 4.0 (TID 6) java.lang.IllegalArgumentException: Invalid format: "2015/06/23 07:57:30" is too short
at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:899)
at DataCreation.ProcessData$.toSec(package.scala:214)
at DataCreation.ProcessData$$anonfun$12.apply(package.scala:106)
at DataCreation.ProcessData$$anonfun$12.apply(package.scala:106)
当我尝试执行该功能时,它会引发以下异常,虽然它对我来说似乎不错?任何帮助将受到高度赞赏。
答案 0 :(得分:1)
你应该放弃"""替换为"
scala> DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").withZone(DateTimeZone.forID("Asia/Hong_Kong")).parseDateTime("2015/06/23 07:57:30").getMillis
res1: Long = 1435017450000