C# 为什么代码不在时间上加3小时?

C# 为什么代码不在时间上加3小时?,c#,datetime,C#,Datetime,它应该在小时数上加上3,但没有,就像addhours行不存在一样。 幸运的是,解决方案非常简单: Literal four = new Literal(); string timeanddate; timeanddate = DateTime.UtcNow.ToString(); DateTime dt = new DateTime(); dt = Convert.ToDateTime(timeanddate); dt.AddHours(3);

它应该在小时数上加上3,但没有,就像addhours行不存在一样。

幸运的是,解决方案非常简单:

    Literal four = new Literal();
    string timeanddate;
    timeanddate = DateTime.UtcNow.ToString();
    DateTime dt = new DateTime();
    dt = Convert.ToDateTime(timeanddate);
    dt.AddHours(3);
    four.Text = "3hr added and this gives>>  " + dt.ToString();
    form1.Controls.Add(four);

幸运的是,解决方案非常简单:

    Literal four = new Literal();
    string timeanddate;
    timeanddate = DateTime.UtcNow.ToString();
    DateTime dt = new DateTime();
    dt = Convert.ToDateTime(timeanddate);
    dt.AddHours(3);
    four.Text = "3hr added and this gives>>  " + dt.ToString();
    form1.Controls.Add(four);