我希望获取日期值以列出每天的新闻。我使用以下内容来获取每一天的价值:
DateTime myDateTime = DateTime.Now;
string datecheck = myDateTime.Day.ToString();
并使用datecheck在当天搜索新闻。 在我的localhost中它是正确的,但我在线上传后。我认为DateTime.Now不起作用。请帮忙。我的代码是asp.net(C#)
代码是这样的:
protected void Page_Load(object sender, EventArgs e)
{
DateTime myDateTime = DateTime.Now;
string datecheck = myDateTime.Day.ToString();
try
{
cnn.Open();
SqlCommand selectreport = new SqlCommand("select * from PowerNews", cnn);
SqlDataReader dr;
dr = selectreport.ExecuteReader();
put = new StringBuilder();
_id.Clear();
_content.Clear();
while (dr.Read())
{
if (dr["PowerNews_postDate"].ToString().Substring(0, 2) == datecheck)
{
_id.Add(dr["PowerNews_Id"].ToString());
_content.Add(dr["PowerNews_content"].ToString());
}
}
dr.Close();
.
.
.}