[英]Convert UTC 'TimeGenerated' to local time in Azure monitor/log/analytics, when using "summarize by"
I have this simple query我有这个简单的查询
MyLog
| summarize avg(executionTimeInMS_d) by bin(TimeGenerated, 5min)
I'd like the summary to be in my local time zone, not UTC.我希望摘要采用我当地的时区,而不是 UTC。 This does not work:
这不起作用:
MyLog
| summarize avg(executionTimeInMS_d) by bin(TimeGenerated-5, 5min)
Can this be done?这可以做到吗?
datetime
values are in UTC. datetime
值采用 UTC。
if you know the timezone offset (at the time you run the query), you can subtract/add it to your datetime
values as explained here: https://docs.microsoft.com/en-us/azure/kusto/query/datetime-timespan-arithmetic如果您知道时区偏移量(在您运行查询时),您可以将其减去/添加到您的
datetime
值,如下所述: https : //docs.microsoft.com/en-us/azure/kusto/query/日期时间跨度算术
for example: print now() - 7h
例如:
print now() - 7h
There is now a "Display time zone" setting in the App Insights query page. App Insights 查询页面中现在有一个“显示时区”设置。 This will convert the timestamp to the selected timezone.
这会将时间戳转换为选定的时区。 It will also show the timezone in the timestamp column heading.
它还将在时间戳列标题中显示时区。
This only seems to work if you output the timestamp directly.仅当您直接输出时间戳时,这似乎才有效。 If you apply any operations it reverts to UTC.
如果您应用任何操作,它将恢复为 UTC。
Best to convert using the datetime_utc_to_local() function.最好使用datetime_utc_to_local() function 进行转换。 This way you can dynamically handle daylight savings within the query and don't need to depend on the UI.
通过这种方式,您可以在查询中动态处理夏令时,而无需依赖 UI。
AzureDiagnostics
| extend CentralTime = datetime_utc_to_local(TimeGenerated, "US/Central")
You can do this by subtracting/adding the time different from UTC.您可以通过减去/添加与 UTC 不同的时间来做到这一点。 For example, to convert to EST.
例如,转换为 EST。 I subtracted 5h from
TimeGenerated
which is in UTC.我从 UTC 的
TimeGenerated
中减去 5h。
AppServiceConsoleLogs
| extend EasternTime = TimeGenerated - 5h
| sort by EasternTime desc
| project Level, EasternTime, ResultDescription
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.