绑定以毫秒表示的日期
我需要使用控制器中的毫秒表示来绑定日期(即从 01.01.1970 开始的毫秒)。我尝试使用 @As("S") 但没有成功,只要值至少为 1000,它就会失败。如果不编写自定义活页夹,真的没有办法做到这一点吗?
编辑:似乎编写自定义活页夹是一种可行的方法,因为 Play 的 DateBinder
使用 SimpleDateFormat
并且由于 此错误。 SimpleDateFormat
不接受这些类型的格式。
I need to bind a Date using the milliseconds representation in a controller (i.e. milliseconds from 01.01.1970). I tried using @As("S")
but had no success, it fails as soon the value is at least 1000. Is there really no way to do this without writing a custom binder?
Edit: Seems like writing a custom binder is the way to go because Play's DateBinder
uses SimpleDateFormat
and because of this bug. SimpleDateFormat
doesn't accept these kinds of formats.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK 没有办法,因为活页夹只是试图解析期望的日期字段(并且日期毫秒字段只是 3 位数字),并且它不会计算任何内容。
最好将毫秒绑定到 Long,然后用它创建 Date。
AFAIK there's no way, because the binder is just trying to parse expecting the date fields (and the Date millisec field are just 3 digit), and it will not calculate anything.
It's better to bind millisecs to Long and then create Date with it.