DateTimeToStringConverter.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Globalization;
  3. using System.Windows.Data;
  4. namespace MediaBrowser.UI.Converters
  5. {
  6. public class DateTimeToStringConverter : IValueConverter
  7. {
  8. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  9. {
  10. var date = (DateTime)value;
  11. string format = parameter as string;
  12. if (string.IsNullOrEmpty(format))
  13. {
  14. return date.ToString();
  15. }
  16. // If a theme asks for this, they know it's only going to work if the current culture is en-us
  17. if (format.Equals("timesuffixlower", StringComparison.OrdinalIgnoreCase))
  18. {
  19. if (CultureInfo.CurrentCulture.Name.Equals("en-US", StringComparison.OrdinalIgnoreCase))
  20. {
  21. var time = date.ToString("t");
  22. var values = time.Split(' ');
  23. return values[values.Length - 1].ToLower();
  24. }
  25. return string.Empty;
  26. }
  27. return date.ToString(format);
  28. }
  29. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  30. {
  31. throw new NotImplementedException();
  32. }
  33. }
  34. }