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

如何使用PowerShell输出含毫秒的文件创建时间?

用PowerShell输出带毫秒的文件创建时间

原命令可获取文件创建时间,但仅显示到秒精度:

Get-ChildItem *_971*.* -Force | Select-Object FullName, CreationTime

直接在Select-Object里调用CreationTime.ToString()会触发报错,因为Select-Object不支持这种直接在属性后调用方法的写法,报错信息如下:

Select-Object : A positional parameter cannot be found that accepts argument 'yyyyMMdd HH:mm:ss.fff'.
At line:1 char:33

要输出带毫秒的创建时间,需使用计算属性(通过哈希表定义),正确命令如下:

Get-ChildItem *_971*.* -Force | Select-Object FullName, @{Name='CreationTimeWithMs'; Expression={$_.CreationTime.ToString('yyyyMMdd HH:mm:ss.fff')}}

说明:

  • @{Name='自定义属性名'; Expression={属性计算逻辑}} 是PowerShell定义计算属性的标准语法
  • $_.CreationTime 指代当前文件对象的创建时间属性,调用ToString()方法并指定包含毫秒的格式字符串
  • 也可用Get-Date命令实现相同格式化效果:
    Get-ChildItem *_971*.* -Force | Select-Object FullName, @{Name='CreationTimeWithMs'; Expression={Get-Date $_.CreationTime -Format 'yyyyMMdd HH:mm:ss.fff'}}
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 21:53:11