传递到云时日期时间发生变化

发布于 2025-01-14 18:59:18 字数 507 浏览 0 评论 0原文

我们有一个 VueJS 应用程序,它将 JSON 对象传递回 WebAPI。 WebApi 位于云中的虚拟机上。

该 JSON 对象将具有日期时间属性以及其他属性。

在 WebApi 中,此日期时间在类 (MyClass.cs) 中定义为:

 public DateTimeOffset MyDate { get; set; }

如果我的示例中传递的日期时间的值 =“2022-03-15 09:00”。我希望 WebApi 不改变该值。

当在我的本地开发 PC 上运行 WebApi 时,这在存储到数据库时有效:“MyObject.MyDate.LocalDateTime”

但是,当将对象发送到云中的 WebApi 时,这会使用偏移量(-4)和调整日期时间增加4小时。日期时间存储为“2022-03-15 13:00”

我的电脑和云虚拟机均采用东部时间(UTC-4)。

为什么有区别?

如何阻止 WebApi 更改传递给它的日期时间?

We have a VueJS app that is passing a JSON object back to the WebAPi. The WebApi is sitting on a VM in the cloud.

This JSON object will have a datetime property, along with other properties.

In the WebApi, this datetime is defined in a class (MyClass.cs) as:

 public DateTimeOffset MyDate { get; set; }

If the value of the passed datetime in my example = "2022-03-15 09:00". I would like to have the WebApi not change the value.

When running the WebApi on my local dev PC, this works when stored to the DB: "MyObject.MyDate.LocalDateTime"

However, when sending the object to the WebApi in the cloud, this adjust the datetime using the offset(-4) and adds 4 hours. The datetime is stored as "2022-03-15 13:00"

My PC and the cloud VM are both on Eastern Time(UTC-4).

Why the difference?

How do I stop the WebApi from changing the DateTime that is passed to it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文