Example #1
0
 public virtual DateTime? GetDate(int tagType, [CanBeNull] TimeZoneInfo timeZone)
 {
     object o = GetObject(tagType);
     if (o == null)
     {
         return null;
     }
     if (o is DateTime)
     {
         return (DateTime)o;
     }
     if (o is string)
     {
         // This seems to cover all known Exif date strings
         // Note that "    :  :     :  :  " is a valid date string according to the Exif spec (which means 'unknown date'): http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/datetimeoriginal.html
         string[] datePatterns = new string[] { "yyyy:MM:dd HH:mm:ss", "yyyy:MM:dd HH:mm", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm" };
         string dateString = (string)o;
         foreach (string datePattern in datePatterns)
         {
             try
             {
                 DateFormat parser = new SimpleDateFormat(datePattern);
                 if (timeZone != null)
                 {
                     parser.SetTimeZone(timeZone);
                 }
                 return parser.Parse(dateString);
             }
             catch (ParseException)
             {
             }
         }
     }
     // simply try the next pattern
     return null;
 }