关于datetime格式:c#ConvertFromUtc方法 – 获取错误

c# ConvertFromUtc method - getting error

我有以下代码:

1
2
3
4
5
6
7
8
9
10
protected void Page_Load(object sender, EventArgs e)
{
    DateTime dt = ConvertFromUtc(DateTime.Now);
}

public DateTime ConvertFromUtc(DateTime dt)
{
    var tz = TimeZoneInfo.FindSystemTimeZoneById(Session["Timezone"].ToString());          
    return TimeZoneInfo.ConvertTimeFromUtc(dt, tz);
}

我收到以下消息:

The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the
Kind property is DateTimeKind.Local, the source time zone must be
TimeZoneInfo.Local. Parameter name: sourceTimeZone.

我试图添加以下内容,但这没有帮助:

1
    DateTime dateTimeToConvert = new DateTime(dt, DateTimeKind.Unspecified);


使用DateTime.UtcNow代替DateTime.Now