powershell json日期格式
从RESTAPI返回的数据为JSON,其中数据/时间的格式为powershell json日期格式,json,api,powershell,date,intune,Json,Api,Powershell,Date,Intune,从RESTAPI返回的数据为JSON,其中数据/时间的格式为 { "userKey": ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤, "userId": "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤", "userEmail": "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤", "userPrincipalName": "¤¤¤¤¤¤¤¤¤¤¤¤¤¤", "displayName": "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤", "intune
{
"userKey": ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤,
"userId": "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤",
"userEmail": "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤",
"userPrincipalName": "¤¤¤¤¤¤¤¤¤¤¤¤¤¤",
"displayName": "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤",
"intuneLicensed": true,
"isDeleted": true,
"startDateInclusiveUTC": "2017-10-16T00:00:00Z",
"endDateExclusiveUTC": "9999-12-31T00:00:00Z",
"isCurrent": true,
"rowLastModifiedDateTimeUTC": "2017-10-17T00:24:11.8233333Z",
"PictureUrl": "¤¤¤¤¤¤¤¤¤¤¤¤.dk"
}
日期/时间格式不正确,数据来自Intune数据仓库API
数据是通过PowerShell请求的我的问题是这是PowerShell Shell错误还是JSON handel数据格式
日期应显示为年月日HH:MM:SS
日期只是一个字符串,其中包含日期ISO-8601(因为JSON没有日期时间类型)。解析日期,然后将其格式化为不同的字符串:
PS> [datetime]::parse("9999-12-31T00:00:00Z").Tostring('MM/dd/yy HH:mm:ss')
12-31-99 01:00:00
我从json进行了转换,然后循环遍历每个Notes属性,如果有更好的方法,请随意评论:)
在我看来,ISO-8601非常有效。JSON没有任何本地方式来描述日期和时间。处理此问题的主要方法是使用包含所见日期的序列化描述的字符串,或使用通常以Unix时间表示的数字(即自1970-01-01以来的UTC秒数)。就可读性、精度和灵活性而言,字符串版本通常是一个明显的赢家。如果您需要更改此格式,则必须在收到数据后进行更改。这是服务器发送的格式。我查看了关于ISO-8610的wiki,
$IntuneCollectionData | get-member -type NoteProperty | foreach-object {
if ($_.value -match "(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+)|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d)|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d)")
{
$NewDateTime = [datetime]::parse("$($_.value)").Tostring('MM/dd/yy HH:mm:ss')
$_.value = $NewDateTime
}
}