时间段计算

 public static string GetRelatedDateTime(object dateTime)
        {
            TimeSpan timeSpan = DateTime.Now - Convert.ToDateTime(dateTime);
            if (timeSpan.Days > 0)
            {
                return timeSpan.Days + "天以前";
            }
            if (timeSpan.Hours > 0)
            {
                return timeSpan.Hours + "小时以前";
            }
            return timeSpan.Minutes + "分钟以前";
        }

posted @ 2012-02-24 11:09  周正明  阅读(413)  评论(0编辑  收藏  举报