简体   繁体   English

带有 Javascript 的 ASP.NET Core DateTime Rest API 转换为 UTC 而不是 java

[英]ASP.NET Core DateTime Rest API with Javascript converts to UTC instead of java

I have a problem with sending data from my react application with data Sat Oct 30 2021 00:00:00 GMT+0800 (Singapore Standard Time) from javascript function new Date() .我在从我的 react 应用程序发送数据时遇到问题,数据为Sat Oct 30 2021 00:00:00 GMT+0800 (Singapore Standard Time)来自 javascript 函数new Date() When receiving from the my ASP.NET Core Rest Web API application, it converted to {10/29/2021 4:00:00 PM} for reason.当从我的 ASP.NET Core Rest Web API 应用程序接收时,它{10/29/2021 4:00:00 PM}原因转换为{10/29/2021 4:00:00 PM} I think what received from ASP.NET was a UTC time conversion from the javascript DateTime that send from my react application.我认为从 ASP.NET 收到的是来自我的反应应用程序发送的 javascript DateTimeUTC时间转换。 Is there a way to not convert the and retain the same data as javascript DateTime when it receives data from my ASP.NET Core application?有没有办法在从我的 ASP.NET Core 应用程序接收数据时不转换并保留与 javascript DateTime相同的数据?

When I sent the time from the front-end page, the time received by the controller was converted.当我从前端页面发送时间时,控制器接收到的时间被转换。 You can use the following methods to convert:您可以使用以下方法进行转换:

dateTime.ToString("r")

Result:结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM