简体   繁体   中英

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”.

For that I wrote the below lines of code in my 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. 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

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.

You might consider explicitly asking a user for their location and use the new location control: https://github.com/Microsoft/BotBuilder-Location for validation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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