Handy DateTimeConverter

You can use this DateTimeConverter to bind all your string values to DateTime controls and vice-versa

 public class DateTimeConverter : IConverter<string, DateTime>
 {
            private static readonly IFormatProvider FormatProvider = 
            (IFormatProvider) CultureInfo.InvariantCulture;

     static DateTimeConverter()
     {
 
     }

     public string Convert(DateTime dateTime)
     {
         return dateTime.ToString(DateTimeConverter.FormatProvider);
     }  

     public DateTime ConvertBack(string dateTimeString)
     {
         return DateTime.Parse(dateTimeString, DateTimeConverter.FormatProvider);
     }
 }

 

Advertisements