Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
 
 
 
 
TitleGet an ISO 8601 compliant timestamp
KeywordsISO, timestamp, time
CategoriesUtilities
 
Use the GetLocalTime API function to the get computer's time. Use Format statements to format the result as in 2002-09-20T15:48:20.220.

Notice how the code uses Right$ to ensure the milliseconds value is left padded with zeros if necessary. For example if GetLocalTime returns 30 milliseconds, the program displays 030.

(Based on a suggestion from Michael Rosquist).

 
' Return an ISO 8601 compliant timestamp.
Private Function GetIsoTimestamp() As String
Dim st As SYSTEMTIME

    ' Get the local date and time.
    GetLocalTime st

    ' Format the result.
    GetIsoTimestamp = _
        Format$(st.wYear, "0000") & "-" & _
        Format$(st.wMonth, "00") & "-" & _
        Format$(st.wDay, "00") & "T" & _
        Format$(st.wHour, "00") & ":" & _
        Format$(st.wMinute, "00") & ":" & _
        Format$(st.wSecond, "00") & "." & _
        Right$("000" & Format$(st.wMilliseconds), 3)
End Function
 
 
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated