Skip to content

DateTimeOffset modelbinding from form is always set to utc in net7 #45338

@yannicsmeets

Description

@yannicsmeets

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hello,

I have the following model that is used as input of a controller method:

public class TestController : ControllerBase
{
    [HttpPost]
    public DateTimeOffset Post([FromForm] InputModel model)
    {
        return model.StartDate;
    }
}

public class InputModel
{
    public DateTimeOffset StartDate { get; set; }
}

When I sent the string '2022-11-29 10:00' in NET6, the local timezone offset (+1 in my case) is used for the DateTimeOffset. However, in NET7, the offset is always 0.

Expected Behavior

I expect the datetimeoffset is parsed with the local timezone offset, if none is provided in the input string.

Steps To Reproduce

https://github.com/yannicsmeets/datetimeoffset-demo

The main branch is net6. In the net7 branch, the target framework is set to net7.0

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

No response

Metadata

Metadata

Assignees

Labels

old-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions