在Windows搜索上更改System.DateModified格式 [英] Change System.DateModified format on Windows Search
问题描述
我正在使用Windows索引搜索和PHP一起搜索成千上万的文件。
I'm using Windows Indexing search together with PHP to search inside thousands of files.
我通过使用PHP COM类来实现它:
I got it working by using the PHP COM class:
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$recordset = new COM("ADODB.Recordset");
$conn - > Open("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';");
$recordset - > Open("SELECT System.ItemName, System.DateModified FROM SYSTEMINDEX WHERE DIRECTORY='file:C:/xxxx/' AND CONTAINS('xxxx')", $conn);
$recordset - > MoveFirst();
while (!$recordset - > EOF) {
echo $recordset - > Fields - > Item("System.ItemName") - > Value."\n";
$recordset - > MoveNext();
}
我正在检索 DateModified
每个元素的字段,我已经意识到它的格式取决于系统配置。可以通过Windows中的控制面板进行设置。
I am retrieving the DateModified
field of each element and I've realized the format of it depends on the System configuration. It is possible to set it through the control panel in Windows.
我想知道是否有任何方法可以获得所需的格式以避免更改它通过在我想运行脚本的每个系统中使用控制面板。
I am wondering if there's any way to get it in the desired format in order to avoid having to change it by using the control panel in every system I want to run the script.
我注意到对象的属性 formatAs
但是我我不确定如何更改它并且文档不是很完整。
I noticed the object has the property formatAs
but I'm not sure how to change it and the documentation is not very complete.
谢谢。
推荐答案
您可以将VT_DATE对象转换为UNIX时间戳,其中 variant_date_to_timestamp 然后使用日期对其进行格式化无论控制面板中的日期格式如何,都应该有效。
You can convert a VT_DATE object into a UNIX timestamp with variant_date_to_timestamp and then format it with date, this should work regardless of the date format in the control panel.
$format = "Y-m-d";
$object = $recordset->Fields->Item("System.DateModified")->Value;
$timestamp = variant_date_to_timestamp($object);
echo date($format, $timestamp) . "\n";
这篇关于在Windows搜索上更改System.DateModified格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!