2017-08-06 32 views
-1

我想在Excel中,计算2个细胞之间经过的时间,通过以下的AutoIt方法:以毫秒为户头,而使用_DateDiff()

_DateDiff ($sType, $sStartDate, $sEndDate) 

我的问题是,这个功能不会在几毫秒到帐户。 它以秒为单位给我经过的时间,但我希望它在秒+毫秒。

有没有人知道如何获得两个单元之间的时间间隔,包括毫秒与AutoIt?

谢谢:)

回答

0
  1. 你可以扩展自己的功能。
  2. 你可以计算出你的数值* 1000和之后的功能/ 1000

    ; #FUNCTION# ==================================================================================================================== 
    ; Author ........: Jos van der Zande 
    ; Modified.......: 
    ; =============================================================================================================================== 
    Func _DateDiff($sType, $sStartDate, $sEndDate) 
        ; Verify that $sType is Valid 
        $sType = StringLeft($sType, 1) 
        If StringInStr("d,m,y,w,h,n,s", $sType) = 0 Or $sType = "" Then 
         Return SetError(1, 0, 0) 
        EndIf 
        ; Verify If StartDate is valid 
        If Not _DateIsValid($sStartDate) Then 
         Return SetError(2, 0, 0) 
        EndIf 
        ; Verify If EndDate is valid 
        If Not _DateIsValid($sEndDate) Then 
         Return SetError(3, 0, 0) 
        EndIf 
        Local $asStartDatePart[4], $asStartTimePart[4], $asEndDatePart[4], $asEndTimePart[4] 
        ; split the StartDate and Time into arrays 
        _DateTimeSplit($sStartDate, $asStartDatePart, $asStartTimePart) 
        ; split the End Date and time into arrays 
        _DateTimeSplit($sEndDate, $asEndDatePart, $asEndTimePart) 
        ; ==================================================== 
        ; Get the differens in days between the 2 dates 
        Local $aDaysDiff = _DateToDayValue($asEndDatePart[1], $asEndDatePart[2], $asEndDatePart[3]) - _DateToDayValue($asStartDatePart[1], $asStartDatePart[2], $asStartDatePart[3]) 
        ; ==================================================== 
        Local $iTimeDiff, $iYearDiff, $iStartTimeInSecs, $iEndTimeInSecs 
        ; Get the differens in Seconds between the 2 times when specified 
        If $asStartTimePart[0] > 1 And $asEndTimePart[0] > 1 Then 
         $iStartTimeInSecs = $asStartTimePart[1] * 3600 + $asStartTimePart[2] * 60 + $asStartTimePart[3] 
         $iEndTimeInSecs = $asEndTimePart[1] * 3600 + $asEndTimePart[2] * 60 + $asEndTimePart[3] 
         $iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs 
         If $iTimeDiff < 0 Then 
          $aDaysDiff = $aDaysDiff - 1 
          $iTimeDiff = $iTimeDiff + 24 * 60 * 60 
         EndIf 
        Else 
         $iTimeDiff = 0 
        EndIf 
        Select 
         Case $sType = "d" 
          Return $aDaysDiff 
         Case $sType = "m" 
          $iYearDiff = $asEndDatePart[1] - $asStartDatePart[1] 
          Local $iMonthDiff = $asEndDatePart[2] - $asStartDatePart[2] + $iYearDiff * 12 
          If $asEndDatePart[3] < $asStartDatePart[3] Then $iMonthDiff = $iMonthDiff - 1 
          $iStartTimeInSecs = $asStartTimePart[1] * 3600 + $asStartTimePart[2] * 60 + $asStartTimePart[3] 
          $iEndTimeInSecs = $asEndTimePart[1] * 3600 + $asEndTimePart[2] * 60 + $asEndTimePart[3] 
          $iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs 
          If $asEndDatePart[3] = $asStartDatePart[3] And $iTimeDiff < 0 Then $iMonthDiff = $iMonthDiff - 1 
          Return $iMonthDiff 
         Case $sType = "y" 
          $iYearDiff = $asEndDatePart[1] - $asStartDatePart[1] 
          If $asEndDatePart[2] < $asStartDatePart[2] Then $iYearDiff = $iYearDiff - 1 
          If $asEndDatePart[2] = $asStartDatePart[2] And $asEndDatePart[3] < $asStartDatePart[3] Then $iYearDiff = $iYearDiff - 1 
          $iStartTimeInSecs = $asStartTimePart[1] * 3600 + $asStartTimePart[2] * 60 + $asStartTimePart[3] 
          $iEndTimeInSecs = $asEndTimePart[1] * 3600 + $asEndTimePart[2] * 60 + $asEndTimePart[3] 
          $iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs 
          If $asEndDatePart[2] = $asStartDatePart[2] And $asEndDatePart[3] = $asStartDatePart[3] And $iTimeDiff < 0 Then $iYearDiff = $iYearDiff - 1 
          Return $iYearDiff 
         Case $sType = "w" 
          Return Int($aDaysDiff/7) 
         Case $sType = "h" 
          Return $aDaysDiff * 24 + Int($iTimeDiff/3600) 
         Case $sType = "n" 
          Return $aDaysDiff * 24 * 60 + Int($iTimeDiff/60) 
         Case $sType = "s" 
          Return $aDaysDiff * 24 * 60 * 60 + $iTimeDiff 
        EndSelect 
    EndFunc ;==>_DateDiff