| 1 | using Core.Librarys; |
| 2 | using System; |
| 3 | using System.Collections.Generic; |
| 4 | using System.Globalization; |
| 5 | using System.Linq; |
| 6 | using System.Text; |
| 7 | using System.Threading.Tasks; |
| 8 | using System.Windows.Data; |
| 9 | using System.Windows.Media; |
| 10 | |
| 11 | namespace UI.Controls.Converters |
| 12 | { |
| 13 | [ValueConversion(typeof(object), typeof(string))] |
| 14 | public class DateTimeConverter : IValueConverter |
| 15 | { |
| 16 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
| 17 | { |
| 18 | if (!(value is DateTime)) |
| 19 | { |
| 20 | return "参数错误"; |
| 21 | } |
| 22 | var dateTime = (DateTime)value; |
| 23 | string pre = dateTime.ToString("yyyy年MM月dd日"); |
| 24 | if (dateTime.Date == DateTime.Now.Date) |
| 25 | { |
| 26 | pre = "今天"; |
| 27 | } |
| 28 | else if (dateTime.Date == DateTime.Now.Date.AddDays(-1).Date) |
| 29 | { |
| 30 | pre = "昨天"; |
| 31 | } |
| 32 | |
| 33 | return $"{pre} {dateTime.ToString("HH点")}"; |
| 34 | } |
| 35 | |
| 36 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
| 37 | { |
| 38 | throw new NotImplementedException(); |
| 39 | } |
| 40 | } |
| 41 | } |