You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell 7.2中如何让ConvertFrom-Json将日期反序列化为字符串

在PowerShell 7.2中保留ConvertFrom-Json的日期字符串解析行为

PowerShell 7.2对ConvertFrom-Json的日期解析逻辑做了调整,默认会将符合ISO格式的日期字符串自动转换为datetime类型。要恢复旧版本中保留日期为字符串的行为,直接使用-DateParseHandling参数并指定None即可。

示例代码

$val = '{ "date":"2022-09-30T07:04:23.571+00:00" }' | ConvertFrom-Json -DateParseHandling None
$val.date.GetType().FullName

执行以上代码后,$val.date的类型会是System.String,而非默认的System.DateTimeOffset或System.DateTime。

参数说明

-DateParseHandling None会强制ConvertFrom-Json不对任何符合日期格式的字符串做类型转换,完全保留JSON中的原始字符串内容,和PowerShell 7.2之前版本的默认行为完全一致。

内容的提问来源于stack exchange,提问作者qvt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 14:50:32