我想获取日期值以列出每天的新闻。我使用以下方法获取每天的值:
DateTime myDateTime = DateTime.Now;
string datecheck = myDateTime.Day.ToString();
并使用 datecheck 搜索当天的新闻。它在我的本地主机中是正确的,但是在我在线上传之后。我认为 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();
.
.
.}