下面是两个文件名:
.getElementsByClass(CLASS_OFFER_NAME)
.firstOrNull()
?.attr("href") // Here need I add prefix to attr href
.orEmpty()
我想根据文件名中的日期进行比较。 如果文件以“ abc”开头,然后与其中的日期进行比较。
我在下面尝试过:
$f1 = "abc_2019_01_30_5816789.bak","xyz_2019_01_26_4690992.bak"
$f2 = "abc_2019_01_31_3142809.bak","xyz_2019_01_27_8319704.bak"
答案 0 :(得分:0)
尝试一下并根据您的要求进行修改:
$f1 = "abc_2019_01_30_5816789.bak"
$f2 = "abc_2019_01_31_3142809.bak"
$regex = '\d{4}_\d{2}_\d{2}'
[String]$f1date = [regex]::match($f1,'\d{4}_\d{2}_\d{2}').Value
$f1date = $f1date.Replace('_','-')
[datetime]$f1date = $f1date
[String]$f2date = [regex]::match($f2,'\d{4}_\d{2}_\d{2}').Value
$f2date = $f2date.Replace('_','-')
[datetime]$f2date = $f2date
if($f1date -lt $f2date) {Write-Host "true"}