123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Data;
- namespace PDF_Office.DataConvert
- {
- /// <summary>
- /// 用于注释 书签等的时间转换
- /// </summary>
- public class StringToDateConvert : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- string date = "";
- if (string.IsNullOrEmpty((string)value) || !Regex.IsMatch(value.ToString(), "(?<=D\\:)[0-9]+(?=[\\+\\-])"))
- {
- date = System.DateTime.Now.ToString("HH:mm");
- }
- else if (Regex.IsMatch(value.ToString(), "(?<=D\\:)[0-9]+(?=[\\+\\-])"))
- {
- string dateStr = Regex.Match(value.ToString(), "(?<=D\\:)[0-9]+(?=[\\+\\-])").Value;
- #region to do
- if (string.Equals(dateStr.Substring(4, 4), DateTime.Now.ToString("MMdd")))
- {//同天
- date = dateStr.Substring(8, 2) + ":" + dateStr.Substring(10, 2);
- }
- else if (string.Equals(dateStr.Substring(0, 4), DateTime.Now.ToString("yyyy")))
- {//同年
- date = dateStr.Substring(4, 2) + "/" + dateStr.Substring(6, 2) + " " + dateStr.Substring(8, 2) + ":" +
- dateStr.Substring(10, 2);
- }
- else
- {
- date = dateStr.Substring(0, 4) + "/" + dateStr.Substring(4, 2) + "/" + dateStr.Substring(6, 2) + " " + dateStr.Substring(8, 2) + ":" +
- dateStr.Substring(10, 2);
- }
- #endregion to do
- //date = dateStr.Substring(4, 2) + "-" + dateStr.Substring(6, 2) + " " + dateStr.Substring(8, 2) + ":" + dateStr.Substring(10, 2);
- }
- return date;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return null;
- }
- }
- }
|