标签:
public string funString_DateNear(int intDays, string strDay)
{
DateTime? dt = null;
string strTmp = strDay;
int intH = 0;
bool isNear = false;
if (strTmp.IndexOf("小时前") >= 0)
{
int.TryParse(strTmp.Replace("小时前", "").Trim(), out intH);
dt = DateTime.Now.AddHours(-intH);
isNear = true;
}
if (strTmp.IndexOf("天前") >= 0)
{
int.TryParse(strTmp.Replace("天前", "").Trim(), out intH);
dt = DateTime.Now.AddHours(-intH);
isNear = true;
}
if (strTmp.IndexOf("分钟前") >= 0)
{
int.TryParse(strTmp.Replace("分钟前", "").Trim(), out intH);
dt = DateTime.Now.AddHours(-intH);
isNear = true;
}
if (!isNear)
{
dt = funDate_StringToDatetime(strDay);
}
if (dt == null)
{
return "";
}
if (((DateTime)dt) > DateTime.Now.AddDays(-intDays))
{
return ((DateTime)dt).ToString("yyyy-MM-dd HH:mm:ss");
}
else
{
return "";
}
}
public DateTime? funDate_StringToDatetime(string strValue)
{
if (Microsoft.VisualBasic.Information.IsDate(strValue))
{
return DateTime.Parse(strValue);
}
else
{
return null;
}
}
标签:
原文地址:http://www.cnblogs.com/it1042290135/p/5564422.html