SharePoint 列表 date/time 字段集通过 REST API 转换为世界时间

SharePoint list date/time field set via REST API converted to universal time

我想在午夜将 date/time 字段设置为一个值:

# Tuesday, May 19, 2015 12:00:00 AM
$Properties = @{CompletedDate = [DateTime]::Today}
...

$Payload = $Properties | ConvertTo-Json

$headers = @{
  "X-HTTP-Method" = "MERGE";
  "If-Match" = "*"
}

Invoke-WebRequest -Uri $url -Method Post -UseDefaultCredentials -Headers $headers -ContentType "application/json" -Body $Payload

不过,日期似乎正在调整为世界时:

<entry>
  <content>
    <m:properties>
      ...
      <d:CompletedDate m:type="Edm.DateTime">2015-05-19T04:00:00</d:CompletedDate>

如果我想要 CompletedDate 实际上是 2015-05-19T00:00:00,确保这一点的最佳方法是什么?

我想一个选项是:

$today = Get-Date -Date ('{0}/{1}/{2} 00:00:00Z' -f (Get-Date).year, (Get-Date).month, (Get-Date).day)

$Properties = @{CompletedDate = $today}

有没有更高效的方法?

由于 SharePoint 需要以本地时间指定日期和时间值,以下示例显示如何保存 2015-05-19T00:00:00 值:

$completedDate = Get-Date -Date "2015-05-19T00:00:00" #UTC
$completedDate = $completedDate.ToLocalTime()   

$ItemProperties = @{  
       Title = "Approval Task"; 
       CompletedDate = $completedDate}