You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用New-AzAutomationSchedule无法设置正确时区的求助

问题分析与解决方案

核心问题

你调用的New-AzAutomation是笔误,正确命令应为New-AzAutomationSchedule。此前错误使用纯时间字符串作为StartTime参数值,导致Azure默认将其解析为UTC时间,结合TimeZone参数转换后出现时间偏差。

正确实现方法

要让作业在美国中部时间(America/Chicago)上午8点执行,且自动处理夏令时,按以下步骤操作:

  1. 获取目标时区对象

    $targetTimeZone = [System.TimeZoneInfo]::FindSystemTimeZoneById("America/Chicago")
    
  2. 创建目标时区的DateTime对象
    生成当天上午8点的中部时间对象(若需指定未来日期,替换[System.DateTime]::Today为具体日期即可):

    $local8AM = [System.DateTime]::Today.AddHours(8)
    $central8AM = [System.TimeZoneInfo]::ConvertTime($local8AM, $targetTimeZone)
    
  3. 调用New-AzAutomationSchedule
    将转换后的中部时间传入StartTime,同时指定TimeZone参数:

    New-AzAutomationSchedule -AutomationAccountName $AccountName -ResourceGroupName $RGName -Name $Name -DayInterval 1 -StartTime $central8AM -TimeZone "America/Chicago"
    

无效原因说明

  • 传入StartTime "0800"时,Azure会将其解析为UTC时间上午8点,因此调度直接设为UTC8点。
  • 添加-TimeZone "America/Chicago"后,Azure会把UTC8点转换为中部时间(夏令时为UTC-5,即8-5=3点;标准时间为UTC-6,即8-6=2点),这就是你看到的偏差。

关键注意事项

  • 必须传入DateTime类型的StartTime,而非纯时间字符串,确保Azure能识别目标时区的时间点。
  • 通过System.TimeZoneInfo创建的时间对象会自动关联时区信息,Azure Automation会根据指定的TimeZone参数自动处理夏令时切换,无需手动计算偏移量。

内容的提问来源于stack exchange,提问作者Curt Crandall

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 03:42:45