How can I remove time from datetime string in dart
183
Solution 1
import 'package:intl/intl.dart'; //note --->>> import package
DateTime parsedDateTime = DateTime.parse('2021-12-12T11:11:00');
String formatDate = DateFormat("yyyy-MM-dd").format(parsedDateTime);
OUTPUT ->
2021-12-12
Solution 2
String _date_and_time = "2021-12-12T11:11:00";
String date = _date_and_time.split("T")[0];
print("Date is : ${date}");
Author by
Binod Bhandari
Updated on November 23, 2022Comments
-
Binod Bhandari 12 months
I have a Date time string
2021-12-12T11:11:00
. I want to remove the substringT11:11:00
, so that I am left with2021-12-12
.Does anyone have any ideas? Please help me.
-
Sonu Saini almost 2 years@BinodBhandari Welcome dude !