Format a datetime in PowerShell to JSON as \/Date(1411704000000)\/

前端 未结 3 1210
感动是毒
感动是毒 2020-12-31 18:49

I want to get the current date as a string in the following format:

\\/Date(1411762618805)\\/

I have been fighting with PowerShell and have trie

3条回答
  •  既然无缘
    2020-12-31 19:24

    I know this is old but Google led me here. I'm using Invoke-RestMethod to send/receive JSON data, including timestamps in the /Date(1411704000000)/ format. I managed to convert from PowerShell to JSON using the following:

    [System.DateTime]$(Get-Date).DateTime
    

    Example:

    @{DateTime = [System.DateTime]$(Get-Date).DateTime} | ConvertTo-Json
    

    Returns:

    {
        "DateTime":  "\/Date(1484023637000)\/"
    }
    

提交回复
热议问题