如何在azure管道的azure cli任务中添加10小时的Get-Date ?



我在下面使用并尝试添加小时数而没有任何运气。这将以UTC格式返回时间,而我希望以相同的格式返回时间,但要提前10小时。


- task: AzureCLI@2
name: date
displayName: dateValue
inputs:
azureSubscription: 'test'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
$date = $(Get-Date -Format yyyy-MM-dd'T'HH:mm:ss)
echo "##vso[task.setvariable variable=date]$date"

要在Azure CLI中的Get-Date命令中添加10个小时,可以使用AddHours方法。

- task: AzureCLI@2
name: date
displayName: dateValue
inputs:
azureSubscription: 'test'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
$date = $(Get-Date).AddHours(10)
$formattedDate = $date.ToString("yyyy-MM-ddTHH:mm:ss")
echo "##vso[task.setvariable variable=date]$formattedDate"

最新更新