1import datetime
2
3date_time_str = '2018-06-29 08:15:27.243860'
4date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S.%f')
5
6print('Date:', date_time_obj.date())
7print('Time:', date_time_obj.time())
8print('Date-time:', date_time_obj)
9
1dependencies:
2 intl: ^0.17.0
3
4import 'package:intl/intl.dart';
5
6DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");
7
8String string = dateFormat.format(DateTime.now()); //Converting DateTime object to String
9
10DateTime dateTime = dateFormat.parse("2019-07-19 8:40:23"); //Converting String to DateTime object