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