今回はVBAにてNow関数では取得できない、ミリ秒単位でシステム時刻を取得します。
1つ目のマクロはUTC標準時をミリ秒単位で取得します。
2つ目のマクロはローカル時刻をミリ秒単位で取得します。
国を日本に設定している場合は日本時間となります。
GetSystemTime
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
' GetSystemTimeで使用する構造体 Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type 'Windows API Declare Sub GetSystemTime Lib "KERNEL32" (lpSystemTime As SYSTEMTIME) '-------------------------------------------------------------------- Public Function Get_MilliTime() As Currency Dim SysTime As SYSTEMTIME ' 開始時刻 '処理時間の算出(API) Call GetSystemTime(SysTime) 'ミリ秒単位(換算値)に変換 With SysTime FP_GET_SYSTIME = CCur(.wHour) * 3600@ + (CCur(.wMinute) * 60@) + _ CCur(.wSecond) + (CCur(.wMilliseconds) / 1000@) End With End Function |
GetLocalTime
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
' GetLocalTimeで使用する構造体 Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type 'Windows API Declare Sub GetLocalTime Lib "KERNEL32" (lpSystemTime As SYSTEMTIME) '------------------------------------------------------------------- Public Function Get_MilliTime() As Currency Dim SysTime As SYSTEMTIME ' 開始時刻 '処理時間の算出(API) Call GetLocalTime(SysTime) 'ミリ秒単位(換算値)に変換 With SysTime FP_GET_SYSTIME = CCur(.wHour) * 3600@ + (CCur(.wMinute) * 60@) + _ CCur(.wSecond) + (CCur(.wMilliseconds) / 1000@) End With End Function |
---コメント---