我有一个转发器,显示用户想要销售的商品。在转发器的一列中,CreateDate
或项目发布的日期显示如下:
//lblExp.Text originally contains 2013-05-24 14:24:08.000
Label lblExp = (Label)e.Item.FindControl("lblExp");
DateTime StartDate = Convert.ToDateTime(lblExp.Text);
DateTime expDate = StartDate.AddDays(30);
int DaysLeft = (expDate - StartDate).Days;
lblExp.Text = DaysLeft.ToString();
当代码执行时,我得到的是30而不是28。
答案 0 :(得分:2)
这是你想说的吗? (将StartDate
替换为DateTime.Now
)
//lblExp.Text originally contains 2013-05-24 14:24:08.000
Label lblExp = (Label)e.Item.FindControl("lblExp");
DateTime StartDate = Convert.ToDateTime(lblExp.Text);
DateTime expDate = StartDate.AddDays(30);
int DaysLeft = (expDate - DateTime.Now).Days; // Replaced here
lblExp.Text = DaysLeft.ToString();