i have a string containing date in format yyyyMMddHHmmss (e.g.) (20180626170555) and i am using following code to convert it into date time
dateTimeFromString(
intl DateFormat
can't cope with your input string as it doesn't have any separators. The whole string gets consumed as the year. However DateTime.parse
does cope with this (nearly). It happens to expect precisely the format you have (again, nearly).
One of the acceptable styles to parse
is 20120227T132700
, which just differs by the T
date/time separator.
Try this:
String date = '20180626170555';
String dateWithT = date.substring(0, 8) + 'T' + date.substring(8);
DateTime dateTime = DateTime.parse(dateWithT);