Exemple #1
0
        /// <summary>
        /// 获取消息时间字符串
        /// </summary>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static string GetMessageTime(EMMessage message)
        {
            if (message == null)
            {
                return(string.Empty);
            }
            DateTime now     = DateTime.Now;
            DateTime msgTime = DCUtilTool.NewDate(message.timestamp());

            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day == now.Day)
            {
                return(msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day + 1 == now.Day)
            {
                return("昨天 " + msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day + 2 == now.Day)
            {
                return("前天 " + msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year)
            {
                return(msgTime.ToString("MM-dd HH:mm"));
            }
            return(msgTime.ToString("yyyy-MM-dd"));
        }
Exemple #2
0
        /// <summary>
        /// 获取时间字符串
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static string GetMessageTime(long time)
        {
            DateTime now     = DateTime.Now;
            DateTime msgTime = DCUtilTool.NewDate(time);

            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day == now.Day)
            {
                return(msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day + 1 == now.Day)
            {
                return("昨天 " + msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day + 2 == now.Day)
            {
                return("前天 " + msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year)
            {
                return(msgTime.ToString("MM-dd HH:mm"));
            }
            return(msgTime.ToString("yyyy-MM-dd"));
        }