'*** v9.C *** www.dieseyer.de ****************************** ' ' Datei: AktuelleDMTFDateTime.vbs ' Autor: Philipp Reiser ' Autor: B.Flemming 29.07.2009 ' Auf: www.dieseyer.de ' ' Wandelt die aktuelle Zeit in das DMTF DateTime Zeitformat. ' (mit Zeitverschiebung; Sommerzeit; DST) ' '*********************************************************** Option Explicit Dim Txt, i ' Warten, bis eine neue Sekunde beginnt Do WScript.Sleep 1 If InStr( Timer(), "," ) = 0 Then Exit Do Loop Do Txt = Txt & AktuelleDMTFDateTime() & vbCRLF ' WScript.Sleep 1 i = i + 1 : If i > 35 Then exit Do Loop MsgBox Txt, , "015 :: " & WScript.ScriptName MsgBox DMTFToDeTime( AktuelleDMTFDateTime ), , "017 :: " & WScript.ScriptName ' MsgBox DMTFToDeTime( "20091112" ), , "019 :: " & WScript.ScriptName ' MsgBox DMTFToDeTime( "200910021355" ), , "020 :: " & WScript.ScriptName ' MsgBox DMTFToDeTime( "20090101023344" ), , "021 :: " & WScript.ScriptName ' MsgBox DMTFToDeTime( "20090729102344.000000+120" ), , "022 :: " & WScript.ScriptName WScript.Quit '*********************************************************** 'http://msdn.microsoft.com/en-us/library/aa387237(VS.85).aspx ' 'CIM-DATETIME 'yyyymmddHHMMSS.mmmmmmsUUU ' 'The following Field Description lists the fields in the formats. ' 'yyyy Four-digit year (0000 through 9999). ' Your implementation can restrict the supported range. ' For example, an implementation can support only the years 1980 through 2099. ' 'mm Two-digit month (01 through 12). 'dd Two-digit day of the month (01 through 31). ' This value must be appropriate for the month. For example, February 31 is not valid. ' However, your implementation does not have to check for valid data. ' 'HH Two-digit hour of the day using the 24-hour clock (00 through 23). 'MM Two-digit minute in the hour (00 through 59). 'SS Two-digit number of seconds in the minute (00 through 59). ' 'mmmmmm Six-digit number of microseconds in the second (000000 through 999999). ' Your implementation does not have to support evaluation using this field. ' However, this field must always be present to preserve the fixed-length nature of the string. ' 'mmm Three-digit number of milliseconds in the minute (000 through 999). ' 's Plus sign (+) or minus sign (-) to indicate a positive or negative offset from Coordinated Universal Times (UTC). ' 'UUU Three-digit offset indicating the number of minutes that the originating time zone deviates from UTC. ' For WMI, it is encouraged, but not required, to convert times to GMT (a UTC offset of zero). ' ' '*** v9.C *** www.dieseyer.de ****************************** Function AktuelleDMTFDateTime() '*********************************************************** Dim DMTF, Tst Tst = Timer ' Die (aktuell) zehntel und hundertstel Sekunden ermitteln. ' Zeit mit zwei Nachkommastellen: 14:25:36,47 ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If InStr( Tst, "," ) Then Tst = Mid( Tst, InStr( Tst, "," ) + 1 ) Else Tst = "" End If If Len( Tst ) < 2 Then Tst = Tst & "0" If Len( Tst ) < 2 Then Tst = Tst & "0" Tst = "." & Tst ' aktuelle DMTF-Zeit (ohne Nachkommastellen) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Set DMTF = CreateObject("WbemScripting.SWbemDateTime") DMTF.SetVarDate Now(), True ' aktuelle DMTF-Zeit um Nachkommastellen erweitern ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tst = Replace( DMTF, ".00", Tst) Set DMTF = nothing AktuelleDMTFDateTime = Tst End Function ' AktuelleDMTFDateTime() '*** v8.6 *** www.dieseyer.de ****************************** Function Zeit2DMTFDateTime( Zeit ) '*********************************************************** ' http://www.dmtf.org/standards/published_documents/DSP0004V2.3_final.pdf Dim Tst, Txt, objWMIService, colTimeZone, objTimeZone, DaylightBias Zeit = CDate( Zeit ) Txt = Year( Zeit ) Tst = Month( Zeit ) : If Len ( Tst ) = 1 Then Tst = "0" & Tst Txt = Txt & Tst Tst = Day( Zeit ) : If Len ( Tst ) = 1 Then Tst = "0" & Tst Txt = Txt & Tst Tst = Hour( Zeit ) : If Len ( Tst ) = 1 Then Tst = "0" & Tst Txt = Txt & Tst Tst = Minute( Zeit ) : If Len ( Tst ) = 1 Then Tst = "0" & Tst Txt = Txt & Tst Tst = Second( Zeit ) : If Len ( Tst ) = 1 Then Tst = "0" & Tst Txt = Txt & Tst Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Set colTimeZone = objWMIService.ExecQuery("Select * from Win32_TimeZone") For Each objTimeZone in colTimeZone Tst = objTimeZone.DaylightBias - objTimeZone.Bias Next Tst = Tst * - 1 Txt = Txt + ".000000+" & Tst : Txt = Replace( Txt, "+-", "-" ) Zeit2DMTFDateTime = Txt End Function ' Zeit2DMTFDateTime( Zeit ) '*** v9.1 *** www.dieseyer.de ****************************** Function DMTFToDeTime( t ) '*********************************************************** ' Tag Monat Jahr Stunden Minuten Sekunden If Len( t ) = 8 Then DMTFToDeTime = Mid( t, 7, 2 ) & "." & Mid( t, 5, 2 ) & "." & Mid( t, 1, 4 ) & " 00:00" If Len( t ) = 12 Then DMTFToDeTime = Mid( t, 7, 2 ) & "." & Mid( t, 5, 2 ) & "." & Mid( t, 1, 4 ) & " " & Mid( t, 9, 2 ) & ":" & Mid( t, 11, 2 ) If Len( t ) > 13 Then DMTFToDeTime = Mid( t, 7, 2 ) & "." & Mid( t, 5, 2 ) & "." & Mid( t, 1, 4 ) & " " & Mid( t, 9, 2 ) & ":" & Mid( t, 11, 2 ) & ":" & Mid( t, 13, 2 ) DMTFToDeTime = CDate( DMTFToDeTime ) End Function ' DMTFToDeTime( t )