0
votes

I have this formatted string date

2020/04/16 (YYYY/MM/DD)

I want to parse this string to Datetime

var string= 2020/04/16
DateTime.parse(string);

Obviusly doesn´t work, doesn´t has a date correct format.

Somebody know what is the best way to parse this string to DateTime?

1
Is corrrect in parse but when i try to convert to Date like this "DateTime.parse(DateFormat('yyyy/MM/dd').parse(string))" return The argument type 'DateTime' can't be assigned to the parameter type 'String'. - El Hombre Sin Nombre
DateFormat.parse already returns a DateTime. You don't need to parse it again. - jamesdlin

1 Answers

-1
votes

try this:

String date = '20180626170555
String dateWithT = date.substring(0, 8) + 'T' + date.substring(8);
DateTime dateTime = DateTime.parse(dateWithT);

or you try this:

savedDateString = "2012-02-27 13:27:00"
DateTime tempDate = DateFormat("yyyy-MM-dd hh:mm:ss").parse(savedDateString);