简体   繁体   中英

When My Bot is hosted on Azure, I'm facing Date Time format issue

I have built a bot in v3 version. I'm using adaptive card to ask user to select date and time. Client side I'm using Direct Line API. When it's tested in Bot Emulator it will work fine. But When my bot is hosted on Azure, Sometimes it throws exception when I compare current date with user entered date. But it works fine sometimes. I'm not able to debug.

Exception : String was not recognized as a valid DateTime.

Edit 1: @TheGeneral Since the value received IAwaitable<IMessageActivity> result is dynamic I'm just comparing Current date with user entered date. Below is how I'm converting current date to local server time.

var info = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
DateTimeOffset localServerTime = DateTimeOffset.Now;
DateTimeOffset usersTime = TimeZoneInfo.ConvertTime(localServerTime, info);
DateTime Todaydate = usersTime.DateTime;

@bradbury9 I was not parsing the date as date format varied with browsers. And also Adaptive card date and time picker are not supported on IE.

Kindly help me in solving this issue.

If you are getting String was not recognized as a valid DateTime , your problem is %100 the user-entered date format that you are trying to parse AND the regional settings of the host operating system. It works on your machine because the date format matches the configuration of your OS. It breaks on Azure because your cloud server is in a different region and is configured for a different date format.

I'm willing to bet that your UI allows entry in a format similar to DD.MM.YYYY but the Azure server is trying to parse it as something like MM.DD.YYYY .

Your solution is to make sure your date entry UI produces a culture-invariant output for the user data. Provide more info about your front end and you may receive more detailed recommendations.

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