目前,我只需用手各具特色的要求:
$json= @"
{ "theDateParam" = "$(GetTodayInJson)" }
"@
Invoke-RestMethod 'http://myServer:myPort/json/reply/TheServiceOperation' -Method Put -Body $json -ContentType 'application/json'
Function GetTodayInJson()
{
$now = [DateTime]::Now.Date
$utcOffset = [TimeZone]::CurrentTimeZone.GetUtcOffset($now)
$utcOffsetString = $utcOffset.ToString("hhmm")
$milliseconds = ($now.Subtract($utcOffset) - (new-object DateTime(1970,1,1,0,0,0,0))).TotalMilliseconds
$result = "\/Date($milliseconds-$utcOffsetString)\/"
return $result
}
這似乎這樣的伎倆。如果沒有偏移量,我的日期到達另一端的時間是錯誤的(實際上我試圖通過在午夜做所有事情來移除時間組件,但沒有偏移量,服務器端的下午6點顯示日期)。
如果有更好的方法來實現這一點,請讓我知道。包括「更改日期格式」的答案不適用於我。
可能是最好的方法。我的筆記似乎把我帶到這個頁面http://stackoverflow.com/questions/33224540/use-json-net-to-parse-json-date-of-format-dateepochtime-offset這似乎是一個非首發,因爲我可以,我使用了不同的格式。 –