From d53f7315de145266e6465d9f95d11d1712b9a91b Mon Sep 17 00:00:00 2001 From: wei <kaede@kaededeMacBook-Air.local> Date: 星期五, 18 十二月 2020 20:55:28 +0800 Subject: [PATCH] 20201218-6 --- HDL_ON/Common/Utlis.cs | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 101 insertions(+), 7 deletions(-) diff --git a/HDL_ON/Common/Utlis.cs b/HDL_ON/Common/Utlis.cs old mode 100644 new mode 100755 index 4597fc4..a0d84c0 --- 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> /// 鍏ㄥ眬鎵撳嵃 @@ -305,15 +303,16 @@ } /// <summary> - /// 鑾峰彇褰撳墠鏃堕棿鎴冲�� - /// </summary> - /// <returns></returns> + /// + /// </summary> + /// <param name="isMilliseconds">鏄惁寰</param> + /// <returns></returns> public static string GetTimestamp(bool isMilliseconds = true) { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 褰撳湴鏃跺尯 if (isMilliseconds) { - return ((long)(DateTime.Now - startTime).TotalMilliseconds).ToString(); // 鐩稿樊绉掓暟 + return ((long)(DateTime.Now - startTime).TotalMilliseconds).ToString(); // 鐩稿樊寰鏁� } else { @@ -329,6 +328,101 @@ 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 < Day) + // { + // //鏄剧ず 鏃�:鍒� + // 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(this DateTime dateTime) + { + var nowDateTime = DateTime.Now; + var subYear = nowDateTime.Year - dateTime.Year; + var subMonth = nowDateTime.Month - dateTime.Month; + var subDay = nowDateTime.Day - dateTime.Day; + + //骞翠唤宸�煎ぇ浜�0 + if(subYear > 0) + { + //鏄剧ず 骞� + return dateTime.ToString("yyyy"); + } + else + { + //鐩稿悓骞翠唤锛屾湀浠藉樊鍊煎ぇ浜�0 + if (subMonth > 0) + { + //鏄剧ず 鏈�:鏃� + return dateTime.ToString("MM/dd"); + } + else + { + //鐩稿悓鏈堜唤锛屾棩鏈熷樊鍊煎ぇ浜�0 + if (subDay > 0) + { + //鏄剧ず 鏈�:鏃� + return dateTime.ToString("MM/dd"); + } + else + { + //鍚屼竴澶╂樉绀� 鏃�:鍒� + return dateTime.ToString("HH:mm"); + } + } + } + } + + /// <summary> + /// 鏃堕棿杞崲 + /// 灏戜簬1澶� 鏄剧ず 鏃跺垎 + /// 灏戜簬涓�骞� 鏄剧ず 鏈堟棩 + /// 澶т簬涓�骞� 鏄剧ず 骞� + /// </summary> + /// <param name="dateTime"></param> + /// <returns></returns> + public static string ToFriendlyDisplay(long unixTimeStamp) + { + return ToFriendlyDisplay(UnixToDateTimeMS(unixTimeStamp)); + } + #endregion + } -- Gitblit v1.8.0