绑定以毫秒表示的日期

发布于 2024-11-26 02:53:48 字数 359 浏览 3 评论 0原文

我需要使用控制器中的毫秒表示来绑定日期(即从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以畏孤独 2024-12-03 02:53:49

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文