How bind input type datetime-local to *time.Time?


How do I bind an HTML field of type “datetime-local” with a pointer field “* time.Time”?

The example about custom binding is a bit confusing in the documentation.


After reading I don’t believe this is handled by the framework. Furthermore, I don’t believe it could be added, since how could the framework possibly know how to parse the raw string? You could be unmarshalling any number of date/time formats into a time.Time field, trying them exhaustively would make little sense (would be way too expensive). The only way that I see is to handle that in your handler, let it bind what the rest, and this one you set it manually after you parse it any way you like.

You could even use something like: though you likely know what format you’re expecting so again, that may be overkill.

Hope it helps!