【asp源码栏目提醒】:网学会员在asp源码频道为大家收集整理了“asp net处理和计算微博发布时间的代码 - 编程语言“提供大家参考,希望对大家有所帮助!
asp.net处理和计算微博发布时间的代码 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 /// /// 把秒转换成分钟 /// /// public static int SecondToMinuteint Second decimal mm decimaldecimalSecond / decimal60 return Convert.ToInt32Math.Ceilingdouble.Parsemm.ToString region 返回某年某月最后一天 /// /// 返回某年某月最后一天 /// ///年份 ///月份 /// 日 public static int GetMonthLastDateint year int month DateTime lastDay new DateTimeyear month new System.Globalization.GregorianCalendar.GetDaysInMonthyear month int Day lastDay.Day return Day endregion region 返回时间差 public static string DateDiffDateTime DateTime1 DateTime DateTime2 string dateDiff null try //TimeSpan ts1 new TimeSpanDateTime1.Ticks //TimeSpan ts2 new TimeSpanDateTime2.Ticks //TimeSpan ts ts1.Subtractts2.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 返回该微博是什么时候发的 /// /// 返回该微博是什么时候发的 /// ///发微博时间 ///当前时间 public static string GetWhenSendTimeDateTime BlogTime DateTime NowTime DateTime t1 BlogTime DateTime t2 NowTime string RES if t2 - t1.TotalMinutes 1440 RES t1.ToStringyyyy年MM月dd日 HH:mm else if t2 - t1.TotalMinutes 60 RES Math.Floort2 - t1.TotalMinutes / 60.ToString 小时 Math.Floort2 - t1.TotalMinutes 60.ToString 分钟前 else if Math.Floort2 - t1.TotalMinutes 60上一篇:2010 ajax 入门篇 Ajax实例—Javascript直接调用服务器C#代码