DateHelper(辅助类)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public static class DateHelper { public static string GetDayOfWeekName(DateTime datetime) { string weekstr = datetime.DayOfWeek.ToString(); switch (weekstr) { case "Monday": weekstr = "周一"; break; case "Tuesday": weekstr = "周二"; break; case "Wednesday": weekstr = "周三"; break; case "Thursday": weekstr = "周四"; break; case "Friday": weekstr = "周五"; break; case "Saturday": case "Sunday": weekstr = "周末"; break; } return weekstr; } public static int ConvertDateTimeInt(string timeStr) { DateTime time = Convert.ToDateTime(timeStr); System.DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new System.DateTime(1970, 1, 1));//.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); return (int)(time - startTime).TotalSeconds; } public static string GetNewsTime(DateTime dtTime) { var time = DateTime.Now; string releaseTime; var seconds = time.Subtract(dtTime).TotalMinutes; if (seconds >= 0 && seconds < 1) { releaseTime = "刚刚"; } else if (seconds >= 1 && seconds < 60) { releaseTime = (int)seconds + "分钟前"; } else if (seconds >= 60 && seconds < 60 * 24) { releaseTime = time.Subtract(dtTime).Hours + "小时前"; } else if (seconds >= 60 * 24 && seconds < 7 * 24 * 60) { releaseTime = time.Subtract(dtTime).Days + "天前"; } else if (seconds >= 7 * 24 * 60 && seconds < 30 * 24 * 60) { releaseTime = (int)(time.Subtract(dtTime).Days / 7) + "周前"; } else if (seconds >= 30 * 24 * 60 && seconds < 12 * 30 * 24 * 60) { releaseTime = (int)(time.Subtract(dtTime).Days / 30) + "月前"; } else if (seconds >= 12 * 30 * 24 * 60) { releaseTime = releaseTime = dtTime.ToString("yyyy-MM-dd"); } else { releaseTime = dtTime.ToString("yyyy-MM-dd"); } return releaseTime; } }