时间差函数列出两个时间内的所有日期

Posted Xiao-C

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了时间差函数列出两个时间内的所有日期相关的知识,希望对你有一定的参考价值。

 1 function DateDiff
 2 {
 3 param([Parameter(Mandatory=$true)][datetime]$starttime,[datetime]$endtime,[string]$formatdate=‘D‘)
 4 [long]$firsttime+=[long]((date $starttime).ToOADate())
 5 [long]$lasttime=(date $endtime).ToOADate()
 6 do
 7 {
 8     [string[]]$result+=(‘{0:‘+$formatdate+‘}‘) -f [System.DateTime]::FromOADate($firsttime)
 9     $firsttime++
10 }
11 until($firsttime -gt $lasttime)
12 return $result
13 }
14 DateDiff 2017/7/1 2017/7/10
15 #还有一个备用参数是缺省值,可不填。

 

以上是关于时间差函数列出两个时间内的所有日期的主要内容,如果未能解决你的问题,请参考以下文章