跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

浏览文件

DateTimeConverter.cs

41 行 · 1.2 KB历史下载
1using Core.Librarys;
2using System;
3using System.Collections.Generic;
4using System.Globalization;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8using System.Windows.Data;
9using System.Windows.Media;
10
11namespace 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}