everyone i am using MongoDB as my backend , i don't have any clues how can i convert DateTime type to ISODate MongoDB , i try to look through document and searching , i can't find anything about it , do you have any idea about this ? thank in advance
Asked
Active
Viewed 569 times
2
-
@JahidulIslam yeah , here what i'm doing right now i want to insert date type from flutter to mongoDB and then get it back as type datetime , but i don't know how can i convert dateTime type on json serialzable package , can you show me how can i do it ? – Heng YouSour Nov 22 '21 at 04:11
1 Answers
2
you can convert dart DateTime to ISO8601Date format with code like this :
DateTime now = DateTime.now();
String isoDate = now.toIso8601String();

Mojtaba Ghiasi
- 823
- 6
- 16
-
no , it isn't what i want , i just want to know how can i convert DateTime type to ISODate type on mongoDB by json_serializable package – Heng YouSour Nov 22 '21 at 08:56
-
you can, do not use the json_serializable package and make your JSON as a string then encrypts to JSON. – Mojtaba Ghiasi Nov 22 '21 at 11:39
-
i can not do that , my whole project completely using json_serializable package , any idea or choice ? – Heng YouSour Nov 23 '21 at 01:11
-
-
-
1@saibot here what i did `@JsonKey( fromJson: CoreModelConverter.convertDateTimeForModel, toJson: CoreModelConverter.convertDateTimeForModel, disallowNullValue: true) final DateTime? createdAt; ` `class CoreModelConverter { static DateTime? convertDateTimeForModel(DateTime? dateTime) => dateTime; }` – Heng YouSour May 24 '22 at 06:30