直截了当的问题,我看不出我在做什么错 - 某处的某些类型不匹配。基本上试图在来自 Web 请求的参数上设置默认的 Long 数据类型。这是代码:
val startTs:Long = params.getOrElse("start_ts", DateTime.yesterdayAsEpoch).toLong
val endTs:Long = params.getOrElse("end_ts", DateTime.todayAsEpoch).toLong
我的 DateTime 帮助代码:
def todayAsEpoch: Long = {
val c = Calendar.getInstance(TimeZone.getTimeZone("EST"))
c.setTime(new java.util.Date())
c.set(c.get(Calendar.YEAR),c.get(Calendar.MONTH),c.get(Calendar.DAY_OF_MONTH),0,0,0)
c.getTimeInMillis / 1000L
}
def yesterdayAsEpoch: Long = {
val c = Calendar.getInstance(TimeZone.getTimeZone("EST"))
c.setTime(new java.util.Date())
c.set(c.get(Calendar.YEAR),c.get(Calendar.MONTH),c.get(Calendar.DAY_OF_MONTH),0,0,0)
((c.getTimeInMillis / 1000L) - 86400)
}
最后,错误:
value toLong is not a member of Any
[error] val startTs:Long = params.getOrElse("start_ts", DateTime.yesterdayAsEpoch).toLong
[error] ^
[error] /vagrant/src/main/scala/com/myapp/api/controllers/FooController.scala:437: value toLong is not a member of Any
[error] val endTs:Long = params.getOrElse("end_ts", DateTime.todayAsEpoch).toLong
[error] ^
[error] two errors found
[error] (compile:compile) Compilation failed