asp.net 处理和计算微博发布时间
2012-01-10 10:32
429 查看
using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace MicroBlogForWP7.Classes { public class TimeParser { /// <summary> /// 把秒转换成分钟 /// </summary> /// <returns></returns> public static int SecondToMinute(int Second) { decimal mm = (decimal)((decimal)Second / (decimal)60); return Convert.ToInt32(Math.Ceiling(double.Parse(mm.ToString()))); } #region 返回某年某月最后一天 /// <summary> /// 返回某年某月最后一天 /// </summary> /// <param name="year">年份</param> /// <param name="month">月份</param> /// <returns>日</returns> public static int GetMonthLastDate(int year, int month) { DateTime lastDay = new DateTime(year, month, new System.Globalization.GregorianCalendar().GetDaysInMonth(year, month)); int Day = lastDay.Day; return Day; } #endregion #region 返回时间差 public static string DateDiff(DateTime DateTime1, DateTime DateTime2) { string dateDiff = null; try { //TimeSpan ts1 = new TimeSpan(DateTime1.Ticks); //TimeSpan ts2 = new TimeSpan(DateTime2.Ticks); //TimeSpan ts = ts1.Subtract(ts2).Duration(); TimeSpan ts = DateTime2 - DateTime1; if (ts.Days >= 1) { dateDiff = DateTime1.Month.ToString() + "月" + DateTime1.Day.ToString() + "日"; } else { if (ts.Hours > 1) { dateDiff = ts.Hours.ToString() + "小时前"; } else { dateDiff = ts.Minutes.ToString() + "分钟前"; } } } catch { } return dateDiff; } #endregion #region 返回该微博是什么时候发的 /// <summary> /// 返回该微博是什么时候发的 /// </summary> /// <param name="year">发微博时间</param> /// <param name="month">当前时间</param> public static string GetWhenSendTime(DateTime BlogTime, DateTime NowTime) { DateTime t1 = BlogTime; DateTime t2 = NowTime; string RES = ""; if ((t2 - t1).TotalMinutes > 1440) { RES = t1.ToString("yyyy年MM月dd日 HH:mm"); } else if ((t2 - t1).TotalMinutes > 60) { RES = Math.Floor(((t2 - t1).TotalMinutes / 60)).ToString() + "小时" + (Math.Floor((t2 - t1).TotalMinutes) % 60).ToString() + "分钟前"; } else { if ((Math.Floor((t2 - t1).TotalMinutes) % 60) <= 0) RES = "刚刚更新"; else RES = (Math.Floor((t2 - t1).TotalMinutes) % 60).ToString() + "分钟前"; } return RES; } #endregion } }
相关文章推荐
- asp.net 处理和计算微博发布时间
- C#处理和计算微博发布时间
- asp.net 发布到IIS中出现”处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”“错误的解决方法
- 在Asp.Net MVC中实现计算页面执行时间及简单流量统计
- asp.net 发布到IIS中出现”处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”“错误的解决方法
- asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler” .
- asp.net页面加载时间计算
- ASP.NET计算在页面停留时间
- asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- 关于ASP.Net中的时间处理
- asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- Asp.net 计算两个时间相差的月份数,不考虑天数 具体几号
- asp.net计算页面执行时间
- asp.net C#计算时间--按照日期确定第几周 按照第几周确定日期范围
- asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- asp.net发布到IIS:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler
- asp.net 有关时间各种(输出)处理
- (转)关于ASP.Net中的时间处理