1. 一天內,顯示幾點幾分
2.兩三天前,顯示為"昨天"、"前天"
3.四天到七天前,顯示星期幾
4.更久以前,顯示日期
public DateTime CreateDate { get; set; } public string CreateDateFormat { get { var diff = new TimeSpan(DateTime.Now.Ticks - CreateDate.Ticks).Days; //判斷超過七天:顯示日期 if (diff > 7) { return CreateDate.ToString("yyyy-MM-dd"); } else if (diff == 1 ) { return "昨天"; } else if (diff == 2) { return "前天"; } else if (diff < 1) { return CreateDate.ToString("tt hh:mm"); } //轉換成星期 else { return CreateDate.ToString("dddd", new System.Globalization.CultureInfo("zh-cn")); } } }
沒有留言:
張貼留言