2

我有一个中继器,它显示用户想要出售的物品。在转发器的一列中,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。

4

1 回答 1

2

这是你想说的吗?(替换StartDateDateTime.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();
于 2013-05-26T15:29:22.003 回答