Created
April 29, 2019 05:16
-
-
Save hasimyerlikaya/d644ceee807ad2b905857e4ed61de9e4 to your computer and use it in GitHub Desktop.
Custom DateTime Converter For Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:json_annotation/json_annotation.dart'; | |
class CustomDateTimeConverter implements JsonConverter<DateTime, String> { | |
const CustomDateTimeConverter(); | |
@override | |
DateTime fromJson(String json) { | |
if (json.contains(".")) { | |
json = json.substring(0, json.length - 1); | |
} | |
return DateTime.parse(json); | |
} | |
@override | |
String toJson(DateTime json) => json.toIso8601String(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment