简体   繁体   English

Datetimeoffset 不适用于 azure 应用服务

[英]Datetimeoffset not working on azure app service

I am working on a method to query an existing table with one of the columns to be datetimeoffset "2021-02-06 05:00:00.0000000 -04:00"我正在研究一种方法来查询现有表,其中一列是 datetimeoffset "2021-02-06 05:00:00.0000000 -04:00"

I have a stored procedure that accepts the startDate and endDate.我有一个接受 startDate 和 endDate 的存储过程。 I want the startDate to be the beginning of the day(startDate) and the end of the day(endDate)我希望 startDate 是一天的开始(startDate)和一天的结束(endDate)

 var DateToStartOfDay = StartDate + " 00:00:01.0000000 -04:00";
 var DateToEndOfDay = EndDate + " 23:59:00.0000000 -04:00";
            //DateTimeOffset.Parse
 var startDate = DateTimeOffset.Parse(DateToStartOfDay);
 var endDate = DateTimeOffset.Parse(DateToEndOfDay).AddDays(1);

The above code works perfectly on my system but one I deploy to Azure App Service, I got this error上面的代码在我的系统上运行良好,但我部署到 Azure App Service 时出现此错误

String '2018-02-29 23:59:00.0000000 -04:00' was not recognized as a valid DateTime."字符串 '2018-02-29 23:59:00.0000000 -04:00' 未被识别为有效的 DateTime。"

I suggest you can set string type in StartDate .我建议您可以在StartDate设置string类型。

My test code我的测试代码

    public string bb(string aa) {
        try
        {
            var DateToStartOfDay = aa + " 00:00:01.0000000 -04:00";
            var startDate = DateTimeOffset.Parse(DateToStartOfDay);
            return startDate.ToString();
        }
        catch (Exception ex)
        {
            return ex.ToString();
            throw;
        }
    }

Test Result测试结果

在此处输入图片说明


Although the Azure web app runs in the sandbox environment, we can use it as a cloud server.虽然 Azure Web 应用在沙盒环境中运行,但我们可以将其用作云服务器。 The local effect should be the same as that deployed in the azure web app.本地效果应该与azure web app中部署的效果一样。 If there is still NULL, it is recommended to add try... catch... to catch the exception.如果还有NULL,建议加上try...catch...来捕捉异常。 Or learn how to remote debug .或者学习如何远程调试

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

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