You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB
C#

using Common.Extensions;
using System;
namespace Common.Helpers
{
public class DateTimeHelper
{
public static string FriendlyDate(DateTime? date)
{
if (!date.HasValue) return string.Empty;
string strDate = date.Value.ToString("yyyy-MM-dd");
string vDate = string.Empty;
if (DateTimeExtension.GetUtcDateTime().ToString("yyyy-MM-dd") == strDate)
{
vDate = "今天";
}
else if (DateTimeExtension.GetUtcDateTime().AddDays(1).ToString("yyyy-MM-dd") == strDate)
{
vDate = "明天";
}
else if (DateTimeExtension.GetUtcDateTime().AddDays(2).ToString("yyyy-MM-dd") == strDate)
{
vDate = "后天";
}
else if (DateTimeExtension.GetUtcDateTime().AddDays(-1).ToString("yyyy-MM-dd") == strDate)
{
vDate = "昨天";
}
else if (DateTimeExtension.GetUtcDateTime().AddDays(-2).ToString("yyyy-MM-dd") == strDate)
{
vDate = "前天";
}
else
{
vDate = strDate;
}
return vDate;
}
}
}