This is my code:
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace FunctionApp66
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation(DateTime.UTCNow.ToString());
return new OkObjectResult("!!!!!!!!!!!!!!!");
}
}
}
After set the WEBSITE_TIME_ZONE
to SA Pacific Standard Time
and deploy, my code works fine on azure:
![enter image description here](https://i.stack.imgur.com/chK1i.png)
console also no problem:
![enter image description here](https://i.stack.imgur.com/rnPU0.png)
So your code should be no problem, you can try below things:
1, restart the function app to let the function app re-load the environment variable, and then try again.
2, try other GMT-5 TIMEZONE, from this doc, they are:
SA Pacific Standard Time
Eastern Standard Time
US Eastern Standard Time
3, convert the TIMEZONE manually in your code:
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace FunctionApp66
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
var date = System.TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("SA Pacific Standard Time"));
log.LogInformation(date.ToString());
return new OkObjectResult("!!!!!!!!!!!!!!!");
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…