Formatter.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Collections.Generic;
  2. namespace Bowin.Web.Controls.Mvc
  3. {
  4. public class FormatterHelper
  5. {
  6. protected static Dictionary<Formatter, string> DictFormatter = new Dictionary<Formatter, string>();
  7. protected static string DefaultFormatter = "";
  8. protected static List<Formatter> DateFormatterList = new List<Formatter>();
  9. static FormatterHelper()
  10. {
  11. DictFormatter.Add(Formatter.None, "");
  12. DictFormatter.Add(Formatter.FullDate, "yyyy-MM-dd HH:mm:ss.S");
  13. DictFormatter.Add(Formatter.ShortDate, "hh:mm:ss");
  14. DictFormatter.Add(Formatter.LongDate, "yyyy-MM-dd HH:mm:ss");
  15. DictFormatter.Add(Formatter.OnlyYearMonth, "yyyy-MM");
  16. DictFormatter.Add(Formatter.OnlyYearMonthDay, "yyyy-MM-dd");
  17. DictFormatter.Add(Formatter.CHSShortDate, "hh时mm分ss秒");
  18. DictFormatter.Add(Formatter.CHSLongDate, "yyyy年MM月dd日 HH时mm分ss秒");
  19. DictFormatter.Add(Formatter.CHSLongDateNoSecond, "yyyy年MM月dd日 HH时mm分");
  20. DictFormatter.Add(Formatter.CHSOnlyYearMonthDay, "yyyy年MM月dd日");
  21. DateFormatterList.Add(Formatter.FullDate);
  22. DateFormatterList.Add(Formatter.ShortDate);
  23. DateFormatterList.Add(Formatter.LongDate);
  24. DateFormatterList.Add(Formatter.OnlyYearMonth);
  25. DateFormatterList.Add(Formatter.OnlyYearMonthDay);
  26. DateFormatterList.Add(Formatter.CHSShortDate);
  27. DateFormatterList.Add(Formatter.CHSLongDate);
  28. DateFormatterList.Add(Formatter.CHSOnlyYearMonthDay);
  29. }
  30. public static string GetFormatterString(Formatter formatter)
  31. {
  32. if (DictFormatter.ContainsKey(formatter))
  33. {
  34. return DictFormatter[formatter];
  35. }
  36. else
  37. {
  38. return DefaultFormatter;
  39. }
  40. }
  41. public static Helper.FormatterType GetFormatterType(Formatter formatter)
  42. {
  43. if (DateFormatterList.Contains(formatter))
  44. return Helper.FormatterType.DateTime;
  45. return Helper.FormatterType.None;
  46. }
  47. }
  48. }