Search code examples
dateplayframeworkpojomilliseconds

Bind a Date in milliseconds representation


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.


Solution

  • 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.