简体   繁体   English

将bot项目代码发布到Azure Web应用程序后如何解决日期时间问题

[英]How to resolve the date time issue after published bot project code into azure web app

I am working on Bot Technology, in my current Bot project I implemented the functionality as “based on time my bot tells greetings to the user like Good Morning, Good After Noon and Good Evening”. 我正在研究Bot Technology,在我当前的Bot项目中,我将该功能实现为“基于我的机器人根据对用户的问候,如早安,中午和晚安”。

For that I wrote the below lines of code in my MessagesController.cs 为此,我在MessagesController.cs中编写了以下代码行

    var hour = todaydate.Hour;
    string sessionOfDay = "";

    if (hour >= 12 && hour <= 17)
    {
        sessionOfDay = "Afternoon";

    }
    else if (hour > 17 && hour <= 23)
    {
        sessionOfDay = "Evening";

    }
    else
    {
        sessionOfDay = "Morning";
    }

The above code working fine in my Local Machine. 上面的代码在我的本地计算机上工作正常。 But when I was published my bot project into azure web app. 但是,当我发布我的机器人项目到azure网络应用程序中时。 After that my bot tells greetings to the user based on server time not an local time. 之后,我的机器人会根据服务器时间而非本地时间告诉用户问候。

Can you please tell me how to fix the above issue? 您能告诉我如何解决上述问题吗?

-Pradeep -Pradeep

In general, unless your users share their location with you, you have no way of knowing what timezone they are in. For users that choose to share their location, you can calculate the offset between sever time (UTC(+0)) and the user's time zone. 通常,除非您的用户与您共享他们的位置,否则您将无法知道他们所在的时区。对于选择共享其位置的用户,您可以计算服务器时间(UTC(+0))与用户的时区。

You might consider explicitly asking a user for their location and use the new location control: https://github.com/Microsoft/BotBuilder-Location for validation 您可能会考虑明确询问用户的位置,并使用新的位置控制: https : //github.com/Microsoft/BotBuilder-Location进行验证

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

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