zoukankan
html css js c++ java
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 { /// <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 } }
查看全文
相关阅读:
Leetcode: Insert Delete GetRandom O(1)
Leetcode: Kth Smallest Element in a Sorted Matrix
Leetcode: Combination Sum IV && Summary: The Key to Solve DP
Leetcode: Wiggle Subsequence
Leetcode: Guess Number Higher or Lower II
Leetcode: Guess Number Higher or Lower
Leetcode: Find K Pairs with Smallest Sums
Leetcode: Super Pow
Leetcode: Largest Divisible Subset
Leetcode: Water and Jug Problem && Summary: GCD求法(辗转相除法 or Euclidean algorithm)
原文地址:https://www.cnblogs.com/javawebsoa/p/2458103.html
最新文章
PHP版本中的VC6,VC9,VC11,TS,NTS区别
linux zip/unzip命令
ajax 设置Access-Control-Allow-Origin实现跨域访问
gulp下静态资源的合并、压缩、MD5后缀
fis3简单教程
linux修改挂载目录
linux下文件的复制、移动与删除
Js 和 PHP 中保留小数点后X位数的方法 toFixed、round、number_format、sprintf
mysql命令语句来去除掉字段中空格字符的方法
mysql binlog to sql and show mysqlstatusadmin
热门文章
Python数据库编程
Mysql权限速查表以及权限详解
linux环境下python的pdb调试方法
MySQL5.7(5.6)GTID环境下恢复从库思路方法(转发)
“大”事务引起的锁等待分析案例
MySQL Binlog解析
MHA failover GTID 专题
MySQL GTID 主从复制错误修复方法
MySQL5.7 GTID 浅析
Leetcode: Insert Delete GetRandom O(1)
Copyright © 2011-2022 走看看