0
我想從時間戳中減去任何秒,其類型爲Double
。如何從雙倍的時間戳中減去秒數?
下面是我想象的功能:
Function subtractSeconds()
Dim timeStamp As Double
Dim timeStampSeconds As Double
timeStamp = Cells(1, 1)
'timeStampSeconds = getSeconds(timeStamp)
'Cells(1, 1) = timeStamp - timeStampSeconds
End Function
這裏是我到目前爲止,與comments幫助。我當然要找的東西更優雅:
Function subtractSeconds()
Dim timeStamp As Double
Dim timeStampHours As Long
Dim timeStampMinutes As Long
Dim timeStampSeconds As Long
timeStamp = Cells(1, 1)
Cells(1, 1) = Format(Cells(1, 1), "yyyy/m/d hh:mm:ss")
timeStampHours = DatePart("h", Cells(1, 1))
timeStampMinutes = DatePart("m", Cells(1, 1))
'timeStampSeconds = DatePart("s", Cells(1, 1))
'something like the following to put the date time back together without seconds
'Cells(1, 1) = Format(Cells(1, 1), "yyyy/m/d") & TimeValue(timeStampHours & ":" & timeStampMinutes & ":" & 0))
'Convert back to double
End Function
查找功能'DartPart'它允許你提取包括秒的日期時間的任何部分。 – 2015-04-03 08:19:25
'DatePart'?看起來很有希望!謝謝! – 2015-04-03 08:20:56