您的位置:首页 > 其它

如何判断一个日期是否属于当前系统本月的日期

2008-04-07 11:38 651 查看

DateTime yourTime = DateTime.Parse("2007-5-1");


DateTime nowTime = DateTime.Now;


if (yourTime.Month == nowTime.Month && yourTime.Year == nowTime.Year)




...{


Label1.Text = "是本月日期";


}


else Label1.Text = "不是";




如何判断一个日期是否属于当前系统本月的日期




dt.Month.CompareTo(DateTime.Now.Month)


年份也是同理.




根据这个做出来了网站本月内新发表的新闻前面加上一个new的图标.




//aspx




<%# getNewState(DataBinder.Eval(Container.DataItem, "news_date"))%>




news_date 是取出表存日期的字段




//cs






加new#region 加new


public static string getNewState(object newsDate)




...{


DateTime dt = Convert.ToDateTime(newsDate);


if(dt.Month.CompareTo(DateTime.Now.Month)==0)




...{


//Response.Write(dt.Month.CompareTo(DateTime.Now.Month));




return "<img src='images/news_date.gif' width='34' height='15'>";


}


else




...{


return "";


}


}


#endregion




注意:dt.Month.CompareTo(DateTime.Now.Month)如果是true返回值为0,false则返回-1

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐