Windows Can';t get Folder.GetDetailsOf()以秒为单位返回文件时间
当我的iPhone连接到我的Windows笔记本电脑时,我正在尝试从iPhone上的文件访问文件创建的时间信息。我已经编写了一个小的PowerShell测试脚本,它成功地实现了这一点,但有一个小缺点:返回文件创建时间的函数不包括秒…(示例输出为“18/03/2017 21:58”。) 如何使Folder.GetDetailsOf()也返回秒数 我尝试应用不同的文化(区域设置):Windows Can';t get Folder.GetDetailsOf()以秒为单位返回文件时间,windows,file,powershell,time,Windows,File,Powershell,Time,当我的iPhone连接到我的Windows笔记本电脑时,我正在尝试从iPhone上的文件访问文件创建的时间信息。我已经编写了一个小的PowerShell测试脚本,它成功地实现了这一点,但有一个小缺点:返回文件创建时间的函数不包括秒…(示例输出为“18/03/2017 21:58”。) 如何使Folder.GetDetailsOf()也返回秒数 我尝试应用不同的文化(区域设置): 使用所需的时间格式设置新的区域性 使用区域性包装所有内容,如上所述 将系统范围的短时格式(在Windows设置中=>
- 使用所需的时间格式设置新的区域性李>
- 使用区域性包装所有内容,如上所述李>
- 将系统范围的短时格式(在Windows设置中=>时钟、语言和区域)设置为“HH:mm:ss”
当然,对于如何解决此问题的任何其他建议也欢迎:)标题是关于从文件夹中获取秒数,但文本是关于将PowerShell区域设置应用于COM对象。请确定您的问题是什么,并使标题与文本匹配。有点晚了,所以您可能不再需要这个了,但我只是偶然发现了这个问题,所以我将回答我的一个问题,“为下一代”,因为它显示了如何使用VBA中的FSO检索文件夹或文件,时间缩短到毫秒(很容易适应VBS)标题是关于从文件夹中获取秒数,但文本是关于将PowerShell区域设置应用于COM对象。请确定您的问题是什么,并使标题与文本匹配。有点晚了,所以您可能不再需要这个了,但我只是偶然发现了这个问题,所以我将回答我的一个问题,“为下一代”,因为它显示了如何使用VBA中的FSO检索文件夹或文件,时间缩短到毫秒(很容易适应VBS)
Function Using-Culture (
[System.Globalization.CultureInfo]$culture = (throw “USAGE: Using-Culture -Culture culture -Script {scriptblock}”),
[ScriptBlock]$script= (throw “USAGE: Using-Culture -Culture culture -Script {scriptblock}”)
) {
$OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
trap {
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
}
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
Invoke-Command $script
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
}
$currentThread = [System.Threading.Thread]::CurrentThread
[System.Globalization.CultureInfo] $culture = "nl-NL"
$culture.DateTimeFormat.LongTimePattern = 'HH:mm:ss'
$culture.DateTimeFormat.ShortTimePattern = 'HH:mm:ss'
$culture.DateTimeFormat.FullDateTimePattern = 'dd MMMM, yyyy HH:mm:ss'
$currentThread.CurrentCulture = $culture
$currentThread.CurrentUICulture = $culture
Using-Culture $culture {
# This outputs the date in Dutch, using the format above;
# if the format above is changed, then Get-Date's output does too
Get-Date
$path = 'C:\Windows\System32\notepad.exe'
$shell = New-Object -COMObject Shell.Application
$folder = Split-Path $path
$file = Split-Path $path -Leaf
$shellfolder = $shell.Namespace($folder)
$shellfile = $shellfolder.ParseName($file)
# GetDetailsOf() on the other hand is oblivious to the newly set culture
$shellfolder.GetDetailsOf($shellfile, 4)
}