public DateTime?photo_exif(string PathToPicture) { doob.Parser Prs = new doob.Parser(); IEnumerable <doob.ExifItem> MetaItemsPhotos = Prs.Parse(PathToPicture); List <doob.ExifItem> ListedMetaItemsPhotos = MetaItemsPhotos.ToList(); foreach (var item in ListedMetaItemsPhotos) { if (item.Id == 306 || item.Id == 36867) { try { DateTimeOffset dto = DateTimeOffset.Parse(item.Value.ToString()); DateTime dtObject = dto.DateTime; return(dtObject); } catch (Exception any) { string format = "yyyy:MM:dd HH:mm:ss"; //if(item.Value.ToString()) DateTime dtObjecvt = (DateTime)item.Value; DateTime dtObject = DateTime.ParseExact(item.Description, format, CultureInfo.InvariantCulture); return(dtObject); } } } return(null); }