Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Converting UTC to Local Time via Azure Functions and Logic Apps
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = "convert/timezone")]HttpRequest req, TraceWriter log)
// Suppress Date/Time string to be converted to DateTime object.
var settings = new JsonSerializerSettings() { DateParseHandling = DateParseHandling.None };
dynamic body = JsonConvert.DeserializeObject(await req.ReadAsStringAsync().ConfigureAwait(false), settings);
var input = (string)body?.input;
var utc = DateTimeOffset.TryParse(input, null, DateTimeStyles.AssumeUniversal, out DateTimeOffset result)
? result
: DateTimeOffset.MinValue;
if (utc == DateTimeOffset.MinValue)
var error = new { messagae = "Invalid Date/Time" };
return new BadRequestObjectResult(error);
var aest = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");
var output = TimeZoneInfo.ConvertTime(utc, aest);
var response = new { input = input, output = output };
return new OkObjectResult(response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment