示例#1
0
 public static string FormatDateTimeForUI(int unixTime)
 {
     return(UIStringFormatterHelper.FormatDateTimeForUI(Extensions.UnixTimeStampToDateTime((double)unixTime, true)));
 }
示例#2
0
        public static string FormatDateTimeForUI(DateTime dateTime)
        {
            DateTime now   = DateTime.Now;
            int      int32 = Convert.ToInt32(Math.Floor((now - dateTime).TotalMinutes));
            string   str1  = dateTime.ToString("HH:mm");

            if (int32 >= -1 && int32 < 60)
            {
                if (int32 < 1)
                {
                    return(CommonResources.MomentAgo.ToLowerInvariant());
                }
                return(UIStringFormatterHelper.FormatNumberOfSomething(int32, CommonResources.OneMinuteFrm, CommonResources.TwoFourMinutes, CommonResources.FiveMinutes, true, null, false));
            }
            if (now.Date == dateTime.Date)
            {
                if (string.IsNullOrEmpty(UIStringFormatterHelper.AtStr(dateTime)))
                {
                    return(string.Format("{0} {1}", CommonResources.Today, str1));
                }
                return(string.Format("{0} {1} {2}", CommonResources.Today, UIStringFormatterHelper.AtStr(dateTime), str1));
            }
            if (now.AddDays(-1.0).Date == dateTime.Date)
            {
                if (string.IsNullOrEmpty(UIStringFormatterHelper.AtStr(dateTime)))
                {
                    return(string.Format("{0} {1}", CommonResources.Yesterday, str1));
                }
                return(string.Format("{0} {1} {2}", CommonResources.Yesterday, UIStringFormatterHelper.AtStr(dateTime), str1));
            }
            if (now.Year == dateTime.Year)
            {
                int    day        = dateTime.Day;
                string ofMonthStr = UIStringFormatterHelper.GetOfMonthStr(dateTime.Month);
                if (string.IsNullOrEmpty(UIStringFormatterHelper.AtStr(dateTime)))
                {
                    return(string.Format("{0} {1} {2}", day, ofMonthStr, str1));
                }
                return(string.Format("{0} {1} {2} {3}", day, ofMonthStr, UIStringFormatterHelper.AtStr(dateTime), str1));
            }
            int    day1                  = dateTime.Day;
            string ofMonthStr1           = UIStringFormatterHelper.GetOfMonthStr(dateTime.Month);
            int    year                  = dateTime.Year;
            string prepositionBeforeYear = CommonResources.PrepositionBeforeYear;
            string str2                  = UIStringFormatterHelper.AtStr(dateTime);

            if (string.IsNullOrEmpty(str2))
            {
                return(string.Format("{0} {1} {2}", day1, ofMonthStr1, str1));
            }
            if (string.IsNullOrEmpty(prepositionBeforeYear))
            {
                if (string.IsNullOrEmpty(str2))
                {
                    return(string.Format("{0} {1} {2} {3}", day1, ofMonthStr1, year, str1));
                }
                return(string.Format("{0} {1} {2} {3} {4}", day1, ofMonthStr1, year, UIStringFormatterHelper.AtStr(dateTime), str1));
            }
            if (string.IsNullOrEmpty(str2))
            {
                return(string.Format("{0} {1} {2} {3} {4}", day1, ofMonthStr1, prepositionBeforeYear, year, str1));
            }
            return(string.Format("{0} {1} {2} {3} {4} {5}", day1, ofMonthStr1, prepositionBeforeYear, year, UIStringFormatterHelper.AtStr(dateTime), str1));
        }
示例#3
0
 public static string FormatDateTimeForTimerAttachment(DateTime dateTime)
 {
     return(string.Format("{0} {1} {2}", dateTime.ToString("dd MMM"), UIStringFormatterHelper.AtStr(dateTime), dateTime.ToString("HH:mm")));
 }