Home > Software engineering >  Why Azure Function parses date as MM/dd/yyyy even if the region has different culture?
Why Azure Function parses date as MM/dd/yyyy even if the region has different culture?

Time:01-29

The Azure Function app is deployed in Central India region where the default format is dd/MM/yyyy HH:mm:ss. The string to date conversion works as expected in local environment (In India region).

In the live version, the string to date conversion is like "MM/dd/yyyy HH:mm:ss tt". What is the reason for this behaviour?

string dateString = "25/12/2020 10:55:58";
DateTime date = DateTime.ParseExact(dateString, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
dateString = date.ToString(); 

// In Local: 25-12-2020 10:55:58  
// In live:  12-25-2020 10:55:58 AM  

Function app location: enter image description here

CodePudding user response:

It looks like it's parsing them the same, but outputting them incorrectly. Try specifying a format in your ToString() function.

The reason for this is that the default output format (when not explicitly specified) is based on the machine it's running on. Your live machine is probably set to non-Indian date formats.

  • Related