asp.Netマイクロブログの公開時間の処理と計算
3550 ワード
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
}
}