Zdeslav Vojkovic's answer is outdated now.
The JSON.encode()
method in dart:convert
has an optional toEncodable
method that is invoked for objects that are not natively serializable to JSON. It's then up to the user to provide a closure that returns an appropriate serialization of the DateTime.