我想将日期/时间字段设置为午夜的值:
# 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}
有更有效的方法吗?
答案 0 :(得分:2)
由于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}