Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell KML生成操作循环中的时间戳_Powershell_Foreach_Timestamp_Kml - Fatal编程技术网

Powershell KML生成操作循环中的时间戳

Powershell KML生成操作循环中的时间戳,powershell,foreach,timestamp,kml,Powershell,Foreach,Timestamp,Kml,我有一段powershell代码,如下所示: $( foreach ($csv in $csvfiles) { $fname = (Get-Item $csv).Basename '<Folder> <name>{0}</name>' -f $fname $( Import-Csv $csv | foreach { '<Placemark> <name>{0} - {1}</na

我有一段powershell代码,如下所示:

$(
foreach ($csv in $csvfiles) {
 $fname = (Get-Item $csv).Basename
 '<Folder>
  <name>{0}</name>' -f $fname
    $(
    Import-Csv $csv | 
    foreach {
    '<Placemark>
     <name>{0} - {1}</name>
     <TimeStamp>
      <begin>{1}</begin>
      <end>{1}</end>
     </TimeStamp>
     <description>Information - {4}</description>
     <styleUrl>#{5}</styleUrl>
     <Point>
      <coordinates>{2},{3}</coordinates>
     </Point>
    </Placemark>

      ' -f $_.Variable, $_.Timestamp, $_.Variable2, $_.Variable3, $_.Variable4, $_.Color
     }
     )
'</Folder>'
   }
)
$(
foreach($csv文件中的csv){
$fname=(获取项目$csv).Basename
'
{0}'-f$fname
$(
导入Csv$Csv|
弗雷奇{
'
{0} - {1}
{1}
{1}
信息-{4}
#{5}
{2},{3}
'-f$\.Variable,$\.Timestamp,$\.Variable2,$\.Variable3,$\.Variable4,$\.Color
}
)
''
}
)
上述代码有效。我试图使我的位置标记持续更长的时间,这样当滑块移出秒字段时,它们不会消失。时间戳的格式为:

2017-07-26T19:03:40Z


有时时间戳会移到41或39秒,当在Google Earth中移动滑块时,您将丢失placemark,因为它以1分钟的增量移动…这就是我想要的。我想为placemark设置一个开始和结束时间戳,将实际时间戳减去20秒,再加上20秒。如何使用下面的代码执行此操作?有没有一种简单的方法可以将秒数减去并添加到时间戳中,然后仍将其用作循环中KML文件的输入?

也许您可以尝试以下方法来去除秒数:

-f $_.Variable, $($_.Timestamp -replace '^(.*)(\d\d)(.*)$','${1}00$3'), $_.Variable2, $_.Variable3, $_.Variable4, $_.Color
$()
:允许首先计算新值

-替换regex,newvalue
:将秒数替换为
00


我使用
${1}
进行第一次捕获,以避免$100意味着什么,第二次捕获被
00
替换,第三次捕获保持原样。

或者是否可以将时间戳中的秒数去掉,以便将位置标记应用于整分钟?Z in
“2017-07-26T19:03:40Z。”
?没有。这只是我键入“正确”的习惯。抱歉,这可能会让人困惑。我将把它移到块段以减少困惑。好主意!我从未想到在变量上实现regex。谢谢!