From bb6ad792b598927a5459a5fb6f6c27fb1aa9e94e Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期四, 17 十二月 2020 14:06:36 +0800
Subject: [PATCH] 20201217-1
---
HDL_ON/Common/Utlis.cs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/HDL_ON/Common/Utlis.cs b/HDL_ON/Common/Utlis.cs
index 906212b..62cb24e 100644
--- a/HDL_ON/Common/Utlis.cs
+++ b/HDL_ON/Common/Utlis.cs
@@ -2,15 +2,13 @@
using Shared;
using System.Text.RegularExpressions;
using System.Text;
-using System.Collections.Generic;
-using System.Collections;
namespace HDL_ON
{
/// <summary>
/// 甯哥敤宸ュ叿绫�
/// </summary>
- public class Utlis
+ public static class Utlis
{
/// <summary>
/// 鍏ㄥ眬鎵撳嵃
@@ -330,7 +328,55 @@
return Language.CurrentLanguage == "Chinese" ? LanguageTypeEnum.CHINESE.ToString() : LanguageTypeEnum.ENGLISH.ToString();
}
-
+
+ #region 鏃堕棿鏍煎紡杞崲
+ private const int Second = 1;
+ private const int Minute = 60 * Second;
+ private const int Hour = 60 * Minute;
+ private const int Day = 24 * Hour;
+ private const int Month = 30 * Day;
+
+ /// <summary>
+ /// 鏃堕棿杞崲
+ /// 灏戜簬1澶� 鏄剧ず 鏃跺垎
+ /// 灏戜簬涓�骞� 鏄剧ず 鏈堟棩
+ /// 澶т簬涓�骞� 鏄剧ず 骞�
+ /// </summary>
+ /// <param name="dateTime"></param>
+ /// <returns></returns>
+ public static string ToFriendlyDisplay(this DateTime dateTime)
+ {
+ var ts = DateTime.Now - dateTime;
+ var delta = ts.TotalSeconds;
+ if (delta < 24 * Hour)
+ {
+ //鏄剧ず 鏃�:鍒�
+ return dateTime.ToString("HH:mm");
+ }
+ else if (delta < 12 * Month)
+ {
+ //鏄剧ず 鏈�:鏃�
+ return dateTime.ToString("MM/dd");
+ }
+ else
+ { //鏄剧ず 骞�
+ return dateTime.ToString("yyyy");
+ }
+ }
+ /// <summary>
+ /// 鏃堕棿杞崲
+ /// 灏戜簬1澶� 鏄剧ず 鏃跺垎
+ /// 灏戜簬涓�骞� 鏄剧ず 鏈堟棩
+ /// 澶т簬涓�骞� 鏄剧ず 骞�
+ /// </summary>
+ /// <param name="dateTime"></param>
+ /// <returns></returns>
+ public static string ToFriendlyDisplay(long unixTimeStamp)
+ {
+ return ToFriendlyDisplay(UnixToDateTimeMS(unixTimeStamp));
+ }
+ #endregion
+
}
--
Gitblit v1.8.0